format-ende 0.1.1

Set of traits allowing to encode/decode data from/to a generic format
Documentation
  • Coverage
  • 93.33%
    14 out of 15 items documented1 out of 12 items with examples
  • Size
  • Source code size: 7.63 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dezajno

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!();
}