BurntSushi / byteorder

Rust library for reading/writing numbers in big-endian and little-endian.
The Unlicense
984 stars 144 forks source link

Feature request: generic read/write functions #211

Closed antonilol closed 3 months ago

antonilol commented 3 months ago

This will allow users to implement a trait (FromToBuf in my code example) for their own types (example: arbitrary size integer from a different crate or u256 from a cryptography crate) to get the same read/write behavior this crate already implements for standard lib types. In my code example I also added functions that use fixed size arrays (#210).

Code example: (feel free to use)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=eaee11ad65f1938039191929d9575332

BurntSushi commented 3 months ago

I am potentially open to #210 although I'd rather you just use std for that, but I'm not keen on adding new traits and entire new abstractions to byteorder. I don't have any plans for major evolutions of byteorder. Folks should probably build new crates if they want something different.

antonilol commented 3 months ago

Okay I get that. Making new crates works, but my primary concern with it is libraries that currently use byteorder, although making a trait like trait MyByteOrder: ByteOrder { ... } probably works and allows users to continue using the marker types (and aliases) of this crate.