1个不稳定版本

0.1.0 2024年2月5日

#70 in #partial


用于 partial-context

MIT AND BSD-2-Clause

9KB
207

部分上下文

确定性部分/上下文变体的基本特质

用法

use partial_context::PartialContext;

#[derive(PartialContext, PartialEq, Eq, Debug, Clone)]
#[context_needs(
    #[derive(Clone)]
)]
pub struct Test {
    pub abc: i64,
    // mark the field (s) as optional with an unsized type marker
    #[context]
    pub c: usize,
}

fn something_that_uses_abc<T: PartialContext<PartialTest, Test>>(test: T) -> i64 {
    test.partial().abc
}

fn abstracted() {
    let parts = PartialTest::new(1);
    let whole = Test { abc: 1, c: 2 };

    assert_eq!(something_that_uses_abc(parts.clone()), 1);
    assert_eq!(something_that_uses_abc(whole.clone()), 1);

    let fin = parts.with_context(2);
    assert_eq!(whole, fin);
}

依赖关系

~0.6–1.1MB
~25K SLoC