#owned #borrowed #cow

borrown

简化无 std 的借用或所有

1 个不稳定版本

0.1.0 2022年2月15日

#2383Rust 模式

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 每月下载量

MIT/Apache

7KB
155

Borrown - 简化无 std 的借用或所有。

crates.io Documentation License

借用或所有,灵感来自 Cow

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
    }
}

无运行时依赖