borrown

Crates.ioborrown
lib.rsborrown
version0.1.0
sourcesrc
created_at2022-02-15 22:26:36.125052
updated_at2022-02-15 22:26:36.125052
descriptionBorrowed or owned, simplified for no-std.
homepage
repositoryhttps://github.com/codx-dev/borrown
max_upload_size
id532958
size18,948
Victor Lopes (vlopes11)

documentation

README

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
    }
}
Commit count: 2

cargo fmt