#owned #borrowed #cow

borrown

Borrowed or owned, simplified for no-std

1 unstable release

0.1.0 Feb 15, 2022

#11 in #borrowed

Download history 453/week @ 2024-07-30 509/week @ 2024-08-06 432/week @ 2024-08-13 527/week @ 2024-08-20 573/week @ 2024-08-27 551/week @ 2024-09-03 318/week @ 2024-09-10 278/week @ 2024-09-17 303/week @ 2024-09-24 340/week @ 2024-10-01 268/week @ 2024-10-08 246/week @ 2024-10-15 276/week @ 2024-10-22 288/week @ 2024-10-29 238/week @ 2024-11-05 181/week @ 2024-11-12

1,014 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