pub struct Requirements {
pub required: Vec<PropertyId>,
pub optional_with_defaults: Vec<(PropertyId, MaterialValue)>,
}Expand description
Declares what a ShadingStrategy needs from a Material before it can
pack it. Checked once when a material is assigned to a strategy, so
mistakes surface immediately instead of as a panic deep in pack().
Fields§
§required: Vec<PropertyId>§optional_with_defaults: Vec<(PropertyId, MaterialValue)>Implementations§
Source§impl Requirements
impl Requirements
pub fn new() -> Self
pub fn require(self, id: PropertyId) -> Self
pub fn optional(self, id: PropertyId, default: MaterialValue) -> Self
Sourcepub fn validate(
&self,
material: &Material,
strategy_name: &'static str,
) -> Result<(), MaterialError>
pub fn validate( &self, material: &Material, strategy_name: &'static str, ) -> Result<(), MaterialError>
Validates that material has every required property. Does not check
types - individual MaterialValue::as_* accessors are the source of
truth for type coercion inside pack().
Sourcepub fn get_or_default<'a>(
&'a self,
material: &'a Material,
id: PropertyId,
) -> Option<&'a MaterialValue>
pub fn get_or_default<'a>( &'a self, material: &'a Material, id: PropertyId, ) -> Option<&'a MaterialValue>
Reads a property from material, falling back to this requirement’s
declared default for optional properties. Returns None if the
property is neither present nor has a declared default.
Trait Implementations§
Source§impl Clone for Requirements
impl Clone for Requirements
Source§fn clone(&self) -> Requirements
fn clone(&self) -> Requirements
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Requirements
impl Debug for Requirements
Source§impl Default for Requirements
impl Default for Requirements
Source§fn default() -> Requirements
fn default() -> Requirements
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Requirements
impl RefUnwindSafe for Requirements
impl Send for Requirements
impl Sync for Requirements
impl Unpin for Requirements
impl UnsafeUnpin for Requirements
impl UnwindSafe for Requirements
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more