Crates.io | borrown |
lib.rs | borrown |
version | 0.1.0 |
source | src |
created_at | 2022-02-15 22:26:36.125052 |
updated_at | 2022-02-15 22:26:36.125052 |
description | Borrowed or owned, simplified for no-std. |
homepage | |
repository | https://github.com/codx-dev/borrown |
max_upload_size | |
id | 532958 |
size | 18,948 |
Borrow or owned, inspired by Cow.
Provide common trait implementations over T
.
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
}
}