An open API service indexing awesome lists of open source software.

https://github.com/synphonyte/codee

Easy and flexible way of encoding and decoding data into either strings or bytes.
https://github.com/synphonyte/codee

Last synced: 7 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# Codee

[![Crates.io](https://img.shields.io/crates/v/codee.svg)](https://crates.io/crates/codee)
[![Docs](https://docs.rs/codee/badge.svg)](https://docs.rs/codee/)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/synphonyte/codee#license)
[![Build Status](https://github.com/synphonyte/codee/actions/workflows/ci.yml/badge.svg)](https://github.com/synphonyte/codee/actions/workflows/ci.yml)

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

This crate provides generic traits for `Encoder`s and `Decoder`s 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:

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

fn store_value(value: T) -> Result<(), CodecError<>::Error, >::Error>>
where
Codec: Encoder + Decoder,
{
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::(42);
store_value::(MyStruct { field: 42 });
```