rust-lang / rust-lang/rust-by-example
Question mark operator incomplete (?)
Nobody has claimed this yet.
- Dominant language
- Handlebars
- Stars
- 8.1k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Looking at the questionmark operator page: https://doc.rust-lang.org/rust-by-example/std/result/question_mark.html
It seems that the introduction fail to mention that the operator could be used in a function that returns an Option too
Example using the Regex module:
fn parse_stuff(input: &str) -> Option<(&str, &str)> {
let re = Regex::new(r"^(\d+)-(\d+)").unwrap();
let caps = re.captures(&input)?;
Some((caps.get(1)?.as_str(), caps.get(2)?.as_str()))
}
#[test]
fn test_parse() {
assert_eq!(parse_stuff("1-33"), Some(("1", "33")));
assert_eq!(parse_stuff("moo"), None);
}
(Since I'm a beginner I'm not comfortable proposing a PR, and maybe I'm wrong alltogether)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust by Example question-mark operator page linked in the issue and compare its introduction with the provided Regex example. Update the explanation to cover use in a function returning Option, using the example to verify the wording and behavior. Done means the page clearly explains both Result and Option use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100