Debian Codegraph @

third_party/rust/clubcard-crlite/examples/inspect.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 use clubcard_crlite::CRLiteClubcard;
6 use std::env::args;
7 use std::path::PathBuf;
8 use std::process::ExitCode;
9
10 fn parse_args() -> Option<PathBuf> {
11 let mut args = args().map(PathBuf::from);
12 let _name = args.next()?;
13 Some(args.next()?)
14 }
15
16 fn main() -> std::process::ExitCode {
17 let Some(filter_path) = parse_args() else {
18 eprintln!("Usage: {} <filter>", args().next().unwrap());
19 return ExitCode::FAILURE;
20 };
21
22 let Ok(filter_bytes) = std::fs::read(&filter_path) else {
23 eprintln!("Could not read filter");
24 return ExitCode::FAILURE;
25 };
26
27 let Ok(filter) = CRLiteClubcard::from_bytes(&filter_bytes) else {
28 eprintln!("Could not parse filter");
29 return ExitCode::FAILURE;
30 };
31
32 println!("{}", filter);
33
34 ExitCode::SUCCESS
35 }