Crate serde_gura

Crate serde_gura 

Source
Expand description

§Serde Gura

Gura is a file format for configuration files. Gura is as readable as YAML and simple as TOML. Its syntax is clear and powerful, yet familiar for YAML/TOML users.

This crate provides Serde implementation for serialize/deserialize Gura format:

use serde_derive::{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(())
}

Structs§

Deserializer
Serializer

Enums§

Error
Types of errors that may occur during serialization/deserialization

Functions§

from_str
from_value
Interpret a gura::GuraType as an instance of type T.
to_string
Serialize the given data structure as a String of Gura.
to_value
Convert a T into gura::GuraType which is an enum that can represent any valid Gura data.

Type Aliases§

Result