Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Config {
- query: String,
- filename: String,
- }
- fn main() {
- let args: Vec<String> = env::args().collect();
- let config = Config::new(&args)
- }
- impl Config {
- fn new(args: &[String]) -> Result<Config, &'static str> {
- // [...]
- let query = args[1].clone();
- let filename = args[2].clone();
- // [...]
- }
- }
- fn main() {
- let config = Config::new(env::args())
- }
- impl Config {
- fn new(mut args: std::env::Args) -> Result<Config, &'static str> {
- args.next();
- let query = match args.next() {
- Some(arg) => arg,
- None => return Err("Didn't get a query string"),
- };
- let filename = match args.next() {
- Some(arg) => arg,
- None => return Err("Didn't get a file name"),
- };
- // [...]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement