Crate broption

source ·
Expand description

Branded Option. for when you need bro’s in your ption’s.

Possibly unsound. Designed for use with selfref.

Examples

use broption::BOption;

// define a resource that needs a separate initialization step.
struct Foo<'bro> {
  name: BOption<'bro, Box<str>>,
}

// define a context wrapper for our resource.
struct Ctx;
impl broption::Wrapper for Ctx {
  type Kind<'bro> = Foo<'bro>;
}

// create an "initialization context".
let initialized = BOption::factory::<Ctx, _>(|factory| {
  // create an uninitialized resource.
  let mut maybeinit = Foo {
    name: factory.new_none(),
  };
  // initialize the resource.
  factory.init(&mut maybeinit.name, Box::from("hello"));
  // return the hopefully-initialized resource.
  maybeinit
});
// use the initialized resource
assert_eq!(&**initialized.name, "hello");

Structs

Traits