io_de_ser

Crates.ioio_de_ser
lib.rsio_de_ser
version0.1.2
sourcesrc
created_at2024-02-03 14:32:56.993653
updated_at2024-02-03 15:18:36.702608
descriptionCrate that allows to read from and write to .io file format.
homepage
repositoryhttps://github.com/IoDeSer/rust-library
max_upload_size
id1125452
size147,155
Maciej (Io-Maciek)

documentation

README

About

Repository stores code for Rust library that allows to read from and write to .io file format.

Functions and plans

The current status of both serialization and deserialization:

  • Primitive types
  • Strings
  • Arrays
  • Vectors
  • Hashmaps
  • Structs (with named fields)
  • Generics
  • Combinations of all above
  • Tuples
  • Tuple structs
  • &str type
  • Slices

Capabilities

  • Serialization of supported types using macro to_io!() using objects reference,
  • Deserialization of supported types using macro from_io!() using .io formatted String and wanted objects type,
  • Only decorative! support for renaming fields in struct in and from .io formatted String using #[io_name()] helper macro using String literal as argument.

See example below for usage of those capabilities.

Example usage

use io_de_ser::*; // 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
    pub age: u8,
    #[io_name("Address")]	// optional renaming
    pub address: Address<T>,
}

#[derive(IoDeSer, Debug)] // required macro derive, Debug is not required
struct Address<T : IoDeSer> {
    pub city: String,
    pub number: T,
    pub street: String,
}

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

    let io_serialization: String = to_io!(&person); // serialization by reference
    /* saving to file for example */
    println!("{}", &io_serialization);

    let person_deserialization : Person<u8> = from_io!(io_serialization, Person<u8>); // deserialization
    println!("{:?}", &person_deserialization);
}
/*
Output:
|
        Name->|John|
        LastName->|Kowalski|
        Age->|21|
        Address->|
                city->|Warsaw|
                number->|65|
                street->|Tęczowa|
        |
|
Person { name: "John", last_name: "Kowalski", age: 21, address: Address { city: "Warsaw", number: 65, street: "Tęczowa" } }
 */
Commit count: 61

cargo fmt