pub fn parse_from_stdin() -> ParserExpand description
Create a parser for the standard input. The source is set to the console and the name is the empty string to indicate this. Errors reading from standard input are ignored for robustness in pipelines.
Examples found in repository?
More examples
examples/book_numbers_float.rs (line 2)
1fn main() {
2 let mut parser = trivet::parse_from_stdin();
3 while !parser.is_at_eof() {
4 match parser.parse_f64_ws() {
5 Err(err) => {
6 println!("ERROR: {}", err);
7 }
8 Ok(value) => {
9 println!(" {}", value);
10 }
11 }
12 }
13}examples/integers.rs (line 14)
12fn main() -> ParseResult<()> {
13 // Make a new parser and wrap the standard input.
14 let mut parser = trivet::parse_from_stdin();
15 match parse_unsigned_integer(&mut parser) {
16 Err(err) => {
17 println!("{}", err);
18 }
19 Ok(value) => {
20 println!("{}", value);
21 }
22 }
23 Ok(())
24}examples/passthrough.rs (line 7)
6pub fn main() -> ParseResult<()> {
7 let mut parser = parse_from_stdin();
8 while !parser.is_at_eof() {
9 // Read some bytes and then write them out.
10 let value = parser.peek_n(57);
11 // We can't use value.len() because that is in bytes, not characters.
12 for _ in value.chars() {
13 parser.consume();
14 }
15 print!("{}", value);
16 }
17 Ok(())
18}examples/book_cookbook_json_names.rs (line 8)
7pub fn main() -> ParseResult<()> {
8 let mut parser = parse_from_stdin();
9 let mut jp = JSONParser::new();
10 let doc = jp.parse_value_ws(&mut parser)?;
11
12 // Look for and print any element for name at the top level, but only if the
13 // input is a JSON object.
14 if let JSON::Object(map) = doc {
15 if let Some(value) = map.get("name") {
16 println!("name is {}", value);
17 }
18 }
19 Ok(())
20}