Crates.io | partial-context-codegen |
lib.rs | partial-context-codegen |
version | 0.1.0 |
source | src |
created_at | 2024-02-05 06:56:53.848331 |
updated_at | 2024-02-05 06:56:53.848331 |
description | Partial Context Types |
homepage | https://github.com/joshua-auchincloss/partial-context |
repository | https://github.com/joshua-auchincloss/partial-context |
max_upload_size | |
id | 1127297 |
size | 9,397 |
Basic traits for deterministic partial / context variants
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);
}