#units #byte #no-std #memory #byte-size #pages

no-std os_units

A library which provides unit types for writing OS

18 unstable releases (3 breaking)

0.4.2 Jun 14, 2021
0.4.0 Apr 28, 2021
0.3.0 Mar 20, 2021
0.2.7 Dec 29, 2020
0.2.5 Oct 30, 2020

#597 in Operating systems

MIT/Apache

22KB
655 lines

os_units

Crates.io docs.rs Rust

This crate provides a data structure for byte size. With the x86_64 crate, you can easily convert the size of physical memory pages into bytes, and bytes into the number of physical memory pages.

Examples

use os_units::Bytes;
use x86_64::structures::paging::{PageSize, Size4KiB};

let bytes_of_kernel = Bytes::new(314159);
let pages_of_kernel = bytes_of_kernel.as_num_of_pages::<Size4KiB>();
assert_eq!(pages_of_kernel.as_usize(), 77);

let bytes_of_pages = pages_of_kernel.as_bytes();
assert_eq!(bytes_of_pages.as_usize(), 315392);

License: MIT OR Apache-2.0


lib.rs:

This crate provides a data structure for byte size. With the x86_64 crate, you can easily convert the size of physical memory pages into bytes, and bytes into the number of physical memory pages.

Examples

use os_units::Bytes;
use x86_64::structures::paging::{PageSize, Size4KiB};

let bytes_of_kernel = Bytes::new(314159);
let pages_of_kernel = bytes_of_kernel.as_num_of_pages::<Size4KiB>();
assert_eq!(pages_of_kernel.as_usize(), 77);

let bytes_of_pages = pages_of_kernel.as_bytes();
assert_eq!(bytes_of_pages.as_usize(), 315392);

Dependencies

~560KB
~11K SLoC