Crates.io | serde_scan |
lib.rs | serde_scan |
version | 0.4.1 |
source | src |
created_at | 2017-08-03 16:31:31.385869 |
updated_at | 2020-12-02 06:46:51.981353 |
description | easily deserialize values from standard input |
homepage | |
repository | https://github.com/tinaun/serde_scan |
max_upload_size | |
id | 26266 |
size | 31,239 |
easily deserialize whitespace seperated data into any rust data structure supported by serde. useful for demos, programming contests, and the like.
current issues:
Vec
or HashMap
. extern crate serde;
extern crate serde_scan;
#[macro_use]
extern crate serde_derive;
#[derive(Deserialize, Debug, PartialEq)]
struct Triple {
a: u32,
b: u32,
c: u32,
}
#[derive(Deserialize, Debug, PartialEq)]
enum Command {
Q,
Help,
Size(usize, usize),
Color(u8),
}
fn main() {
let s = "1 2 3";
let a: [u32; 3] = serde_scan::from_str(s).unwrap();
assert_eq!(a, [1, 2, 3]);
let b: (u32, u32, u32) = serde_scan::from_str(s).unwrap();
assert_eq!(b, (1, 2, 3));
let c: Triple = serde_scan::from_str(s).unwrap();
assert_eq!(c, Triple { a: 1, b: 2, c: 3 });
let s = "Size 1 2";
let size = serde_scan::from_str(s).unwrap();
assert_eq!(c, Command::Size(1, 2));
}