pub enum Computed<T> {
Literal(T),
Expr(String),
}Expand description
A scenario value that is either a plain literal or, prefixed with =,
an expression to evaluate.
#[serde(untagged)]: deserialization tries Literal(T) first, falling
back to Expr(String) only when the JSON value doesn’t fit T. That
ordering is why this works cleanly for the numbers and strictly-typed
colours this issue targets — a JSON string can never satisfy a numeric
T, so "= $W/2" always falls through to Expr — but is a deliberate
non-goal for Computed<String>: there, every JSON string
("= ..." included) already satisfies Literal(String) first and
Expr is never reached. Schema fields that want expression support are
expected to use a strictly-typed T (a number, or a colour type with
its own validating Deserialize), not a bare String.
This type carries no evaluation logic of its own — resolving an
Expr(String) variant means calling Expr::parse on its contents and
then Expr::eval (or folding it statically, see the crate::expr
module doc) — deliberately, so this crate does not have to hand back an
opinion on when that happens; that is a decision for whatever owns the
field (the static-folding pass, or the per-frame engine context).
Variants§
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Computed<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Computed<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: JsonSchema> JsonSchema for Computed<T>
impl<T: JsonSchema> JsonSchema for Computed<T>
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreimpl<T: PartialEq> StructuralPartialEq for Computed<T>
Auto Trait Implementations§
impl<T> Freeze for Computed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Computed<T>where
T: RefUnwindSafe,
impl<T> Send for Computed<T>where
T: Send,
impl<T> Sync for Computed<T>where
T: Sync,
impl<T> Unpin for Computed<T>where
T: Unpin,
impl<T> UnsafeUnpin for Computed<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Computed<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more