Crate contra

source ·
Expand description

Lightweight and easy to use serialization, deserialization.

Provides abstract serialization into specific formats. Additionally provides the functionality to save and load the serialized content directly from and to disk.

To implement more data formats see: Serializer, Deserializer

Examples

use proc_contra::{Serialize, Deserialize};
use lib_contra::{error::SuccessResult, position::Position, persistent::Persistent};

#[derive(Serialize, Deserialize)]
struct Point {
    x: f32,
    y: f32,
    z: f32
}

fn modify_point() -> Result<(), Box<dyn std::error::Error>> {
    let mut p = Point::load("path/to/point.json")?;
    assert_eq!(p.x, 1.0f32);
    p.x = 2.0f32;
    p.save("path/to/point.json")?;
    Ok(())
}

Re-exports

Modules

Traits

Derive Macros

  • Derives the Deserialize trait implementation
  • Derives the Serialize trait implementation