Skip to content

Commit

Permalink
Improve example in "CLI arguments as data type"
Browse files Browse the repository at this point in the history
Show the complete `main()` function.
Also, fix code indentation and a wrong line number in include.
  • Loading branch information
stomar committed Nov 4, 2023
1 parent d65ee86 commit 6c5a73e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/tutorial/cli-args-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ struct Cli {
}

fn main() {
let pattern = std::env::args().nth(1).expect("no pattern given");
let path = std::env::args().nth(2).expect("no path given");

let pattern = std::env::args().nth(1).expect("no pattern given");
let path = std::env::args().nth(2).expect("no path given");
let args = Cli {
pattern: pattern,
path: std::path::PathBuf::from(path),
};

let args = Cli {
pattern: pattern,
path: std::path::PathBuf::from(path),
};
}
4 changes: 2 additions & 2 deletions src/tutorial/cli-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ way of looking at CLI arguments fits very well. Let's start with this (in file
`src/main.rs`, before `fn main() {`):

```rust,ignore
{{#include cli-args-struct.rs:3:7}}
{{#include cli-args-struct.rs:3:6}}
```

This defines a new structure (a [`struct`])
Expand All @@ -89,7 +89,7 @@ and build the structure ourselves.
It would look something like this:

```rust,ignore
{{#include cli-args-struct.rs:10:15}}
{{#include cli-args-struct.rs:8:16}}
```

This works, but it's not very convenient.
Expand Down

0 comments on commit 6c5a73e

Please sign in to comment.