offer-cell 0.1.2

A rust library that defines a pattern for providing a reference to stored data, and optionally transferring ownership of that data.
Documentation
  • Coverage
  • 84.21%
    16 out of 19 items documented0 out of 16 items with examples
  • Size
  • Source code size: 7.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 336.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rhedgeco/offer-cell
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rhedgeco

Offer Cell

A rust library that defines a pattern for providing a reference to stored data, and optionally transferring ownership of that data.

Usage

Initialization

// a cell may be created
let cell = OfferCell::new(42);

// or initialzed as empty
let empty = OfferCell::empty();

Accessing Data

// access the item as a reference
match cell.item() {
    Some(value) = (), // do something with the value
    None => (), // returns none if there is no item
}

// access the item as a mutable reference
match cell.item_mut() {
    Some(value) = (), // do something with the value
    None => (), // returns none if there is no item
}

Offering Data

What sets this apart, is the data within the cell can be "offered"

// if the cell contains an item, it can be offered
let offered = cell.offer() {
    Some(offered) => offered,
    None => return,
};

// the offered item implements Deref and DerefMut
assert_eq!(offered.deref(), &42);

// if nothing else is done with the offered item,
// the data will stay in the cell for later

// alternatively the offering can be consumed
// this leaves nothing in the cell, and takes ownership of the data
let data = offered.take();