boow

Crates.ioboow
lib.rsboow
version0.1.3
sourcesrc
created_at2018-04-10 10:41:02.789585
updated_at2018-04-10 11:46:48.00395
description`Borrow Or oWned` smart pointer. Alternative to Cow.
homepage
repositoryhttps://github.com/malikolivier/boow
max_upload_size
id59854
size7,901
Malik Olivier Boussejra (malikolivier)

documentation

http://boussejra.com/rust-doc/boow/boow

README

Borrowed-Or-oWned

Provide a Borrowed-Or-oWned smart pointer.

Alternative to Cow for which the Clone trait is not required for the encapsulated type.

Use this crate if you want something like Cow but your type cannot be cloned.

You can find the rustdoc here.

How to use

extern crate boow;
use boow::Bow;
// This struct contains a type for which we cannot know at compile time
// whether it will be owned or borrowed.
struct MyStruct<'a> {
    borrowed_or_owned: Bow<'a, InnerStruct>,
}
struct InnerStruct {
    _stuff: String,
}
impl<'a> MyStruct<'a> {
    // Use borrowed value
    fn from_borrowed(inner: &'a InnerStruct) -> Self {
        Self { borrowed_or_owned: Bow::Borrowed(inner) }
    }
    // Use owned value
    fn from_owned(inner: InnerStruct) -> Self {
        Self { borrowed_or_owned: Bow::Owned(inner) }
    }
}

no_std

If you're interested in using this crate with no_std and the alloc crate, add the following to Cargo.toml:

[dependencies]
boow = { version = "0.1", default-features = false }
Commit count: 15

cargo fmt