#owned #borrowed #cow

borrown

Borrowed or owned, simplified for no-std

1 unstable release

0.1.0 Feb 15, 2022

#2383 in Rust patterns

Download history 411/week @ 2024-03-14 585/week @ 2024-03-21 556/week @ 2024-03-28 475/week @ 2024-04-04 623/week @ 2024-04-11 658/week @ 2024-04-18 585/week @ 2024-04-25 575/week @ 2024-05-02 436/week @ 2024-05-09 473/week @ 2024-05-16 379/week @ 2024-05-23 426/week @ 2024-05-30 482/week @ 2024-06-06 491/week @ 2024-06-13 569/week @ 2024-06-20 508/week @ 2024-06-27

2,115 downloads per month

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