4 releases

Uses old Rust 2015

0.1.3 Apr 10, 2018
0.1.2 Apr 10, 2018
0.1.1 Apr 10, 2018
0.1.0 Apr 10, 2018

#682 in Memory management

Download history 496/week @ 2024-07-20 394/week @ 2024-07-27 383/week @ 2024-08-03 361/week @ 2024-08-10 748/week @ 2024-08-17 981/week @ 2024-08-24 1359/week @ 2024-08-31 1141/week @ 2024-09-07 1364/week @ 2024-09-14 1584/week @ 2024-09-21 1274/week @ 2024-09-28 1547/week @ 2024-10-05 1539/week @ 2024-10-12 1611/week @ 2024-10-19 1444/week @ 2024-10-26 1601/week @ 2024-11-02

6,451 downloads per month
Used in 8 crates (4 directly)

MIT license

7KB
119 lines

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 }

Dependencies

~8KB