#cow #owned #borrowed

borrown

Borrowed or owned, simplified for no-std

1 unstable release

Uses new Rust 2021

0.1.0 Feb 15, 2022

#9 in #owned

Download history 893/week @ 2022-08-03 953/week @ 2022-08-10 909/week @ 2022-08-17 716/week @ 2022-08-24 1056/week @ 2022-08-31 1290/week @ 2022-09-07 1051/week @ 2022-09-14 1481/week @ 2022-09-21 1041/week @ 2022-09-28 1298/week @ 2022-10-05 1419/week @ 2022-10-12 1197/week @ 2022-10-19 1903/week @ 2022-10-26 2832/week @ 2022-11-02 1668/week @ 2022-11-09 1271/week @ 2022-11-16

8,068 downloads per month
Used in 49 crates (via fuel-crypto)

MIT/Apache

7KB
155 lines

Borrown - Borrowed or owned, simplified for no-std.

crates.io Documentation License

Borrow or owned, inspired by Cow.

Provide common trait implementations over T.

Example

use borrown::Borrown;

#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Foo {
    pub _val: usize,
}

let x = Foo { _val: 0 };
let b = Borrown::Borrowed(&x);

let _: &Foo = b.as_ref();
let _: &mut Foo = b.clone().as_mut();
let _: Borrown<'_, Foo> = Default::default();
let _: usize = *b;
let _: bool = b == Borrown::Borrowed(&x);
let _: bool = b <= Borrown::Borrowed(&x);
let _: Borrown<'_, Foo> = b.clone();
let _: Foo = b.into_owned();

println!("{:?}", Borrown::Borrowed(&x));

impl core::ops::Deref for Foo {
    type Target = usize;

    fn deref(&self) -> &usize {
        &self._val
    }
}

No runtime deps