macro_rules! select {
($($module:ident)::+ : .. $spread:ty) => { ... };
($($module:ident)::+ :) => { ... };
($($module:ident)::+ : $field:ident, .. $spread:ty) => { ... };
($($module:ident)::+ : $field:ident ?, .. $spread:ty) => { ... };
($($module:ident)::+ : $field:ident -, .. $spread:ty) => { ... };
($($module:ident)::+ : $field:ident < $presence:ty >, .. $spread:ty) => { ... };
($($module:ident)::+ : $field:ident) => { ... };
($($module:ident)::+ : $field:ident,) => { ... };
($($module:ident)::+ : $field:ident ?) => { ... };
($($module:ident)::+ : $field:ident ?,) => { ... };
($($module:ident)::+ : $field:ident -) => { ... };
($($module:ident)::+ : $field:ident -,) => { ... };
($($module:ident)::+ : $field:ident < $presence:ty >) => { ... };
($($module:ident)::+ : $field:ident < $presence:ty >,) => { ... };
($($module:ident)::+ : $field:ident ?, $($rest:tt)+) => { ... };
($($module:ident)::+ : $field:ident -, $($rest:tt)+) => { ... };
($($module:ident)::+ : $field:ident < $presence:ty >, $($rest:tt)+) => { ... };
($($module:ident)::+ : $field:ident, $($rest:tt)+) => { ... };
}Expand description
Construct a FieldSet by selecting fields from a module.
§Presence States
| Suffix | Presence | Field Type |
|---|---|---|
| (none) | Present | T |
? | Optional | Option<T> |
- | Absent | PhantomData<T> |
Access is always user.field. In generic code use .get() from the Access trait.
§Syntax Reference
| Pattern | Description |
|---|---|
select!(mod: field) | field is Present (required) |
select!(mod: field?) | field is Optional |
select!(mod: field-) | field is Absent |
select!(mod: field<P>) | field has custom presence type P |
select!(mod: all) | all fields Present |
select!(mod: all?) | all fields Optional |
select!(mod: all-) | all fields Absent |
select!(mod: f1, f2?) | multiple fields (f1=Present, f2=Optional) |
select!(mod: f, ..F) | spread: f=Present, rest inherited from F |
select!(mod: f?, ..F) | spread: f=Optional, rest inherited from F |
select!(mod: f, all-) | f=Present, all others Absent |
§Examples
ⓘ
// Concrete types for API boundaries
type Create = select!(user: name, email); // Both required
type Update = select!(user: name?, email?); // Both optional
// Generic: add id field to any existing fields
type WithId<F: user::Fields> = select!(user: id, ..F);
// Function using concrete type
fn create(user: User<Create>) -> User<WithId<Create>> { ... }