1 unstable release

0.1.0 Feb 5, 2024

#77 in #partial


Used in partial-context

MIT AND BSD-2-Clause

9KB
207 lines

Partial Context

Basic traits for deterministic partial / context variants

Usage

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

Dependencies

~0.5–1MB
~22K SLoC