Crates.io | format-ende |
lib.rs | format-ende |
version | 0.1.1 |
created_at | 2025-09-22 13:25:21.892303+00 |
updated_at | 2025-09-22 17:55:31.163257+00 |
description | Set of traits allowing to encode/decode data from/to a generic format |
homepage | |
repository | https://codeberg.org/CoffeJunkStudio/format-ende |
max_upload_size | |
id | 1850026 |
size | 8,154 |
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.
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!();
}