Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
djkoloski committed Sep 10, 2023
1 parent 1ff5031 commit 87b40c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ rend is a library that provides endian-aware primitives for Rust.
```rust
use rend::*;

let little_int = i32_le::new(0x12345678);
let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!([0x78, 0x56, 0x34, 0x12], unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) });
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::new(0x12345678);
let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!([0x12, 0x34, 0x56, 0x78], unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) });
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
Expand Down
14 changes: 10 additions & 4 deletions crates-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ rend is a library that provides endian-aware primitives for Rust.
```rust
use rend::*;

let little_int = i32_le::new(0x12345678);
let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!([0x78, 0x56, 0x34, 0x12], unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) });
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::new(0x12345678);
let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!([0x12, 0x34, 0x56, 0x78], unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) });
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
Expand Down

0 comments on commit 87b40c3

Please sign in to comment.