Crate iodeser

source ·
Expand description

§IoDeSer

IoDeSer is a open-source project that allows to deserialize and serialize objects into .io formatted String.

IoDeSer defines traits, methods, macros and implementations for basic Rust types. See this crate’s source code for additional information.

Currently supports the below types:

  • Vec
  • HashMap<K, V>
  • Array [T; N]
  • Tuples (T1, T2…)
  • Primitive types (un/signed integer, char, float, boolean)
  • String
  • HashSet
  • BinaryHeap
  • BTreeSet
  • LinkedList
  • VecDeque
  • HashMap<T, K>
  • BTreeMap<T, K>

§Status

This crate is in alpha status and should not be used in production environment.

§Design

The main foundation of this project is cross-language compatibility. See the project account for more information about other language libraries status, goals and status.

§Examples

use iodeser::*; // required import

#[derive(IoDeSer, Debug)] // required macro derive IoDeSer, Debug is not required
struct Person<T: IoDeSer> {
    #[io_name("Name")]      // optional renaming
    pub name: String,
    #[io_name("LastName")]  // optional renaming
    pub last_name: String,
    #[io_name("Age")]       // optional renaming
    #[io_order(LAST)]       // optional ordering using FIRST or LAST keyword
    pub age: u8,
    #[io_name("Address")]   // optional renaming
    #[io_order(FIRST)]      // optional ordering using FIRST or LAST keyword
    pub address: Vec<Address<T>>,
}

#[derive(IoDeSer, Debug)] // required macro derive, Debug is not required
struct Address<T: IoDeSer> {
    #[io_order(3)]          // optional ordering using integer
    pub city: String,
    #[io_order(1)]          // optional ordering using integer
    pub number: T,
    #[io_order(2)]          // optional ordering using integer
    pub street: String,
}

fn main() {
    let person = Person::<u8> {
        name: "John".to_string(),
        last_name: "Kowalski".to_string(),
        age: 21,
        address: vec![
            Address::<u8> {
                city: "Warsaw".to_string(),
                number: 65,
                street: "Tęczowa".to_string(),
            },
            Address::<u8> {
                city: "Hamburg".to_string(),
                number: 220,
                street: "Strasse".to_string(),
            }
        ],
    };

    let io_serialization: String = to_io!(&person); // serialization
    println!("{}", &io_serialization);

   let person_deserialization: Person<u8> = from_io!(io_serialization, Person<u8>).unwrap(); // deserialization
    println!("{:?}", &person_deserialization);
}

Macros§

  • Deserializes .io formatted String into Self.
  • Serialize this value via reference into .io file format.

Enums§

  • Represents all errors that might occur during deserialization.

Traits§

  • Trait for serializing and deserializing objects into .io formatted String.

Type Aliases§

Derive Macros§

  • Procedural macro which implements IoDeSer trait for Rust structs using derive attribute.