Crate binver[][src]

Expand description

Binary (de)serialization framework that is backwards compatible with versioned fields.


#[derive(Serializable, PartialEq, Debug)]
pub struct Player {
    // This field has existed since binary version 0.0.1
    #[since(0.0.1)]
    pub id: u32,

    // In 0.0.2 we introduced a new field
    // When loading a serialized 0.0.1 object, this field will have it's `Default` value
    #[since(0.0.2)]
    pub name: String,
}

let player = Player {
    id: 5,
    name: String::from("foo")
};

let serialized = binver::to_vec(&player);
let deserialized_player = binver::deserialize_slice(&serialized).unwrap();

assert_eq!(player, deserialized_player);

Structs

ReadConfig

Configuration passed to a read function

Version

SemVer version as defined by https://semver.org.

Enums

ReadError

Error thrown while reading

WriteError

Error thrown while writing

Traits

Reader

Generic reader

Serializable

The main trait of this crate that is used for (de)serialization

Writer

Generic writer

Functions

deserialize_slice

Deserialize an object from the given slice.

deserialize_slice_with_config

Deserialize an object from the given slice with the given ReadConfig. See ReadConfig for information on the options.

to_vec

Serialize the given Serialiazable object to a vec

write_to_slice

Serialize the given Serializable object to the given slice. The amount of bytes written is returned.

Type Definitions

ReadResult

Result type to be returned from any read action

WriteResult

Result type to be returned from any write action

Derive Macros

Serializable