#endian #byteorder #order #byte #defined #type #default

no-std endian-type-rs

Type safe wrappers for types with a defined byte order

2 releases

Uses old Rust 2015

0.1.4 May 28, 2020
0.1.3 May 28, 2020

#917 in Embedded development

Download history 201/week @ 2024-07-24 127/week @ 2024-07-31 117/week @ 2024-08-07 180/week @ 2024-08-14 238/week @ 2024-08-21 159/week @ 2024-08-28 141/week @ 2024-09-04 483/week @ 2024-09-11 435/week @ 2024-09-18 485/week @ 2024-09-25 420/week @ 2024-10-02 409/week @ 2024-10-09 495/week @ 2024-10-16 544/week @ 2024-10-23 810/week @ 2024-10-30 579/week @ 2024-11-06

2,510 downloads per month
Used in 2 crates (via fdt-rs)

MIT license

9KB
181 lines

endian-type-rs

A fork of endian-type which includes support for no-std and the From trait.

Usage

Add this to your Cargo.toml:

[dependencies.endian-type-rs]
version = "0.1.4"

and this to your crate root:

extern crate endian_type_rs;

Features

This crate can be used without the standard library (#![no_std]) by disabling the default std feature. Use this in Cargo.toml:

[dependencies.endian-type-rs]
version = "0.1.4"
default-features = false
# features = ["num"]    # <--- Uncomment if you wish to include support for num::ToPrimitive

The "num" feature will add additional definitions for simplified casting via the num crate "num".

Previously casting between the internal types and another built-in numeric type required a decent amount of boilerplate. In the worst case you needed to specify both the current Big/LittleEndian's underlying type as well as the type you were trying to cast to. E.g.

let val: u32_be = u32_be::from(10);
let addr = u32::from(val) as usize;

This isn't much overhead here where the type is obvious, however if you change the underlying type of "val" in the above example, you must change every single cast. Now the above becomes:

let val: u32_be = u32_be::from(10);
let addr = val.to_usize().unwrap();

Dependencies

~73KB