pages 0.2.0

A dynamically-sized heap-backed data page. Comprises a user-chosen header and data array packed into a single allocation.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented3 out of 3 items with examples
  • Size
  • Source code size: 28.95 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.81 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • irrustible/pages
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jjl

pages

License Package Documentation

A dynamically-sized heap-backed data page. Comprises a user-chosen header and data array packed into a single allocation.

Usage

use pages::Page;
// A really crappy replacement for Box<Option<usize>>
struct Maybe(Page::<bool, usize>);
impl Maybe {
    fn new() -> Self { Maybe(Page::new(false, 1)) }
    fn put(&mut self, value: usize) {
        *self.0.header_mut() = true; // occupied
        let item: *mut usize = self.0.data_mut()[0].as_mut_ptr();
        unsafe { item.write(value); }
    }
    fn get(&mut self) -> Option<usize> {
        if !(*self.0.header()) { return None; }
        let item: *mut usize = self.0.data_mut()[0].as_mut_ptr();
        *self.0.header_mut() = false; // free
        Some(unsafe { *item })
    }
}

fn main() {
    let mut maybe = Maybe::new();
    assert_eq!(maybe.get(), None);
    maybe.put(42);
    assert_eq!(maybe.get(), Some(42));
}

Copyright and License

Copyright (c) 2021 James Laver, pages contributors.

Licensed under Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0), with LLVM Exceptions (https://spdx.org/licenses/LLVM-exception.html).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.