#deserialize #serialization #serde #data-structures #scanf

serde_scan

easily deserialize values from standard input

7 unstable releases

Uses old Rust 2015

0.4.1 Dec 2, 2020
0.4.0 Nov 23, 2020
0.3.2 Dec 8, 2018
0.2.0 Nov 21, 2018
0.1.0 Aug 3, 2017

#1205 in Encoding

Download history 129/week @ 2024-06-19 75/week @ 2024-06-26 58/week @ 2024-07-03 155/week @ 2024-07-10 111/week @ 2024-07-17 121/week @ 2024-07-24 128/week @ 2024-07-31 148/week @ 2024-08-07 99/week @ 2024-08-14 72/week @ 2024-08-21 90/week @ 2024-08-28 80/week @ 2024-09-04 62/week @ 2024-09-11 121/week @ 2024-09-18 169/week @ 2024-09-25 138/week @ 2024-10-02

504 downloads per month
Used in tm-interpreter

MIT/Apache

25KB
682 lines

serde_scan

easily deserialize whitespace seperated data into any rust data structure supported by serde. useful for demos, programming contests, and the like.

current issues:

  • no support for enums with struct variants
  • structs or tuples cannot contain an unbounded container, like a Vec or HashMap.

examples

    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));
    }

Dependencies

~110–345KB