Skip to content

Easy and flexible way of encoding and decoding data into either strings or bytes.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Synphonyte/codee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codee

Crates.io Docs MIT/Apache 2.0 Build Status

Easy and flexible way of encoding and decoding data into either strings or bytes.

This crate provides generic traits for Encoders and Decoders as well as several implementations for commonly used (de)serializer crates.

This makes it easily possible to abstract away the serialization and deserialization independent of the concrete crate used. You can write a function like this:

use codee::{CodecError, Decoder, Encoder};

fn store_value<T, Codec>(value: T) -> Result<(), CodecError<<Codec as Encoder<T>>::Error, <Codec as Decoder<T>>::Error>>
where
    Codec: Encoder<T, Encoded = String> + Decoder<T, Encoded = str>,
{
    let encoded = Codec::encode(&value).map_err(CodecError::Encode)?;
    let decoded = Codec::decode(&encoded).map_err(CodecError::Decode)?;

    Ok(())
}

// Then we can use it like this:

use codee::string::{JsonSerdeCodec, FromToStringCodec};

#[derive(serde::Serialize, serde::Deserialize)]
struct MyStruct {
    field: usize,
}

store_value::<i32, FromToStringCodec>(42);
store_value::<MyStruct, JsonSerdeCodec>(MyStruct { field: 42 });

About

Easy and flexible way of encoding and decoding data into either strings or bytes.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

 
 
 

Languages