9 releases
0.1.8 | Apr 1, 2024 |
---|---|
0.1.7 | Oct 17, 2023 |
0.1.5 | Jul 5, 2022 |
0.1.4 | Nov 25, 2021 |
0.1.0 | Aug 30, 2021 |
#1536 in Parser implementations
385 downloads per month
36KB
867 lines
Serde Gura
This crate is a Rust library for using the Serde serialization framework with data in Gura file format.
This library does not re-implement a Gura parser; it uses the gura-rs-parser which is a pure Rust Gura 1.0.0 implementation.
Dependency
Add the following dependencies to your Cargo.toml
:
[dependencies]
serde = "1.0"
serde_gura = "0.1.8"
If you want to use Serialize
/Deserialize
traits you must specify the derive feature in your Cargo.toml
:
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_gura = "0.1.8"
Using Serde Gura
API documentation is available but the general idea is:
use serde::{Deserialize, Serialize};
use serde_gura::Result;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Database {
ip: String,
port: Vec<u16>,
connection_max: u32,
enabled: bool,
}
fn main() -> Result<()> {
// You have some type.
let database = Database {
ip: "127.0.0.1".to_string(),
port: vec![80, 8080],
connection_max: 1200,
enabled: true,
};
// Serialize it to a Gura string
let database_str = serde_gura::to_string(&database)?;
let expected = r#"
ip: "127.0.0.1"
port: [80, 8080]
connection_max: 1200
enabled: true
"#;
assert_eq!(database_str, expected.trim());
// Deserialize it back to a Rust type
let deserialized_database: Database = serde_gura::from_str(&database_str)?;
assert_eq!(database, deserialized_database);
Ok(())
}
License
Serde Gura is distributed under the terms of the MIT license.
Dependencies
~5.5MB
~97K SLoC