4 releases (2 breaking)
0.2.1 | Mar 28, 2019 |
---|---|
0.2.0 | Mar 28, 2019 |
0.1.0 | Mar 28, 2019 |
0.0.1 | Dec 22, 2018 |
#969 in Encoding
32 downloads per month
Used in 2 crates
220KB
5.5K
SLoC
SANE-rs
SANE Serialization and Deserialization for Rust
Spec: https://opensource.bloom.sh/sane
Compatible with SANE version: v1.0.0
Usage
//! An example showing off the usage of `Deserialize` to automatically decode
//! SANE into a Rust `struct`
#![deny(warnings)]
use sane;
use serde::{Deserialize};
/// This is what we're going to decode into. Each field is optional, meaning
/// that it doesn't have to be present in SANE.
#[derive(Debug, Deserialize)]
struct Config {
global_string: Option<String>,
global_integer: Option<u64>,
server: Option<ServerConfig>,
peers: Option<Vec<PeerConfig>>,
}
/// Sub-structs are decoded from tables, so this will decode from the `[server]`
/// table.
///
/// Again, each field is optional, meaning they don't have to be present.
#[derive(Debug, Deserialize)]
struct ServerConfig {
ip: Option<String>,
port: Option<u64>,
}
#[derive(Debug, Deserialize)]
struct PeerConfig {
ip: Option<String>,
port: Option<u64>,
}
fn main() {
let sane_str = r#"
global_string = "test"
global_integer = 5
server = { ip = "127.0.0.1", port = 80 }
peers = [
{
ip = "127.0.0.1",
port = 8080,
},
{ ip = "127.0.0.1" },
]
"#;
let decoded: Config = sane::from_str(sane_str).unwrap();
println!("{:#?}", decoded);
}
Contributing
Thank you for your interest in contributing! Please refer to https://opensource.bloom.sh/contributing for guidance.
License
See LICENSE.txt
and https://opensource.bloom.sh/licensing
From an original work by alexcrichton: toml-rs - commit d729bf9c53fcfe8f1e5506a938b88d81526b55a4
Dependencies
~110–345KB