wiwi_wasm/
builder_api.rs

1//! Common builder API stuffs
2//!
3//! # Checklist™
4//!
5//! - struct definition mimicing the function call name
6//! - use statements
7//! - impl block on the struct for "starting" builder methods
8//! - builder struct (with repr(transparent), `inner`, `__marker`)
9//! - builder inner struct
10//! - state trait
11//! - state container struct
12//! - type definitions for important states
13//! - impl state for statecontainer
14//! - impl builder uninit
15//! - impl blocks for finished ones with `call` or `build` fns
16//! - impl block for builder fns, `change_state`, internal functions etc
17
18pub struct Init {
19	__private: ()
20}
21
22pub struct Uninit {
23	__private: ()
24}
25
26// todo ???
27#[diagnostic::on_unimplemented(
28	message = "a required field is not initialised",
29	// label = "this field is not initialised",
30	note = "call a builder method for the missing required field before building"
31)]
32pub trait IsInit {}
33
34impl IsInit for Init {}
35
36// todo ???
37#[diagnostic::on_unimplemented(
38	message = "this field is already initialised",
39	label = "this field is already initialised",
40	note = "omit this builder method call, or a previous builder method call that has set this field, or call a builder method to erase this field"
41)]
42pub trait IsUninit {}
43
44impl IsUninit for Uninit {}
45
46pub trait InitStatus {
47	const IS_INIT: bool;
48	const IS_UNINIT: bool = !Self::IS_INIT;
49}
50
51impl InitStatus for Init {
52	const IS_INIT: bool = true;
53}
54
55impl InitStatus for Uninit {
56	const IS_INIT: bool = false;
57}
58
59pub type PhantomDataInvariant<T> = std::marker::PhantomData<fn(T) -> T>;