Skip to content

Instantly share code, notes, and snippets.

@gregberns
Last active April 9, 2020 22:02
Show Gist options
  • Save gregberns/78b3dde91c29ceeff566a38bc791b0d6 to your computer and use it in GitHub Desktop.
Save gregberns/78b3dde91c29ceeff566a38bc791b0d6 to your computer and use it in GitHub Desktop.
Programming Problem - Parse File

Programming Problem - Parse File

  • Either read the "File Contents" from a file or place the text into a multi-line block
  • Parse the contents
  • Aggregate the time (last field)
  • Report of total calls
  • Report any error cases (non-200)
    • Bonus points: report what line number the error occured on

File Contents

GET /hello/world 200 2s
POST /create/obj 400 3s
PUT /update/world 500 6s
DELETE /end/times 200 3s

Example Output

Total time: 14s
Total calls: 4

Errors:
POST /create/obj 400 3s
PUT /update/world 500 6s

Requirements

Note: "domain" object is refering to an internal memory structure - not a string. Hint: either a Rust struct or enum.

  • GET, POST, PUT, DELETE - should be a domain object
  • 200, 400, 500 - should be a domain object

References

  • Mutli-line strings (ref)
let shader = r#"
    Hello,
    How are you.
    Nice to see you.
"#;
  • Read from file (ref)
use std::fs;

let contents = fs::read_to_string(filename)
        .expect("Something went wrong reading the file");

println!("With text:\n{}", contents);
  • Splitting a string on a character (ref)

  • Trim - trim() and trim_matches() will remove characters from the start and end of strings (ref)

"a12345a".trim_matches('a') == "12345"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment