Thanks to visit codestin.com
Credit goes to lib.rs

#format #io #utility #data

format-ende

Set of traits allowing to encode/decode data from/to a generic format

2 releases

Uses new Rust 2024

0.1.1 Sep 22, 2025
0.1.0 Sep 22, 2025

#1417 in Encoding

21 downloads per month
Used in 2 crates

Apache-2.0

7KB
83 lines

This crate provides the FormatInfo, FormatEncoder, and FormatDecoder traits. These traits allow to encode/decode data from/to a generic format.

Example

use format_ende::FormatInfo;
use format_ende::FormatEncoder;

/// Print given value encoded with the given encoder
fn print<E, V>(encoder: &mut E, value: &V) where
    E: FormatInfo,
    E: FormatEncoder<V>,
    E::EncodeError: std::fmt::Debug,
{
    println!(
        "{} as {}:",
        std::any::type_name::<V>(),
        encoder.file_extension()
    );
    let mut stdout = std::io::stdout();
    encoder.encode(&mut stdout, value).unwrap();
    println!();
}

format-ende

This crate defines the core traits for encoding and decoding data to/from a generic format. It provides a unified interface for various serialization formats, allowing to write code that is agnostic to the underlying format.

Example

use format_ende::FormatInfo;
use format_ende::FormatEncoder;

/// Print given value encoded with the given encoder
fn print<E, V>(encoder: &mut E, value: &V) where
    E: FormatInfo,
    E: FormatEncoder<V>,
    E::EncodeError: std::fmt::Debug,
{
    println!(
        "{} as {}:",
        std::any::type_name::<V>(),
        encoder.file_extension()
    );

    // We don't care what the underlying format is here, we just know that we want to output to stdout
    let mut stdout = std::io::stdout();
    encoder.encode(&mut stdout, value).unwrap();
    println!();
}

No runtime deps