pub enum Expression<T> {
Constant(T),
ZoomStops(Vec<(f32, T)>),
FeatureState {
key: String,
fallback: T,
},
GetProperty {
key: String,
fallback: T,
},
Interpolate {
input: Box<NumericExpression>,
stops: Vec<(f32, T)>,
},
Step {
input: Box<NumericExpression>,
default: T,
stops: Vec<(f32, T)>,
},
Match {
input: Box<StringExpression>,
cases: Vec<(String, T)>,
fallback: T,
},
Case {
branches: Vec<(BoolExpression, T)>,
fallback: T,
},
Coalesce(Vec<Expression<T>>),
}Expand description
A typed expression that evaluates to a value of type T.
This is the core representation for all style property values. The variants range from plain literals to data-driven expressions that depend on feature properties, zoom level, and feature state.
§Backward compatibility
StyleValue<T> is a type alias for this type, so all existing code
that uses StyleValue::Constant(...), StyleValue::ZoomStops(...),
or StyleValue::FeatureState { .. } continues to work unchanged.
Variants§
Constant(T)
Constant literal value.
ZoomStops(Vec<(f32, T)>)
Zoom-keyed stops with linear interpolation.
FeatureState
Value driven by a per-feature state key.
Fields
fallback: TDefault value when the key is absent.
GetProperty
Read a feature property and convert to T.
Equivalent to MapLibre ["get", "property_name"].
Falls back to fallback when the property is missing or
cannot be converted to T.
Fields
fallback: TValue to use when the property is absent or incompatible.
Interpolate
Interpolate between stops based on a numeric input expression.
Equivalent to MapLibre ["interpolate", ["linear"], input, z0, v0, z1, v1, ...].
Fields
input: Box<NumericExpression>The numeric input value (typically Expression::Zoom or a property).
Step
Step function: returns the stop value for the greatest stop ≤ input.
Equivalent to MapLibre ["step", input, default, z0, v0, z1, v1, ...].
Fields
input: Box<NumericExpression>The numeric input.
default: TDefault value when input is below all stops.
Match
Pattern match on a string input expression.
Equivalent to MapLibre ["match", input, label1, val1, ..., fallback].
Fields
input: Box<StringExpression>The string input to match against.
fallback: TValue when no case matches.
Case
Conditional branches evaluated in order.
Equivalent to MapLibre ["case", cond1, val1, cond2, val2, ..., fallback].
Fields
branches: Vec<(BoolExpression, T)>Branches: (condition, output_value).
fallback: TValue when no condition is true.
Coalesce(Vec<Expression<T>>)
Return the first non-null result from a list of expressions.
Equivalent to MapLibre ["coalesce", expr1, expr2, ...].
Implementations§
Source§impl<T: StyleInterpolatable> Expression<T>
impl<T: StyleInterpolatable> Expression<T>
Sourcepub fn evaluate_with_context(&self, ctx: StyleEvalContext) -> T
pub fn evaluate_with_context(&self, ctx: StyleEvalContext) -> T
Evaluate with a zoom-only legacy context.
Sourcepub fn evaluate_with_full_context(&self, ctx: &StyleEvalContextFull<'_>) -> T
pub fn evaluate_with_full_context(&self, ctx: &StyleEvalContextFull<'_>) -> T
Evaluate with a full legacy context (zoom + feature state).
Sourcepub fn evaluate_with_properties(&self, ctx: &ExprEvalContext<'_>) -> T
pub fn evaluate_with_properties(&self, ctx: &ExprEvalContext<'_>) -> T
Evaluate with feature properties for data-driven styling.
Sourcepub fn eval_full(&self, ctx: &ExprEvalContext<'_>) -> T
pub fn eval_full(&self, ctx: &ExprEvalContext<'_>) -> T
Core evaluation entry point.
Source§impl<T> Expression<T>
impl<T> Expression<T>
Sourcepub fn feature_state_key(key: impl Into<String>, fallback: T) -> Self
pub fn feature_state_key(key: impl Into<String>, fallback: T) -> Self
Create a feature-state-driven expression.
Sourcepub fn is_feature_state_driven(&self) -> bool
pub fn is_feature_state_driven(&self) -> bool
Whether this expression depends on per-feature mutable state.
Sourcepub fn is_data_driven(&self) -> bool
pub fn is_data_driven(&self) -> bool
Whether this expression depends on feature properties.
Source§impl Expression<f32>
impl Expression<f32>
Sourcepub fn zoom_interpolate(stops: Vec<(f32, f32)>) -> Self
pub fn zoom_interpolate(stops: Vec<(f32, f32)>) -> Self
Interpolate linearly on zoom: ["interpolate", ["linear"], ["zoom"], z0, v0, z1, v1, ...].
Sourcepub fn zoom_step(default: f32, stops: Vec<(f32, f32)>) -> Self
pub fn zoom_step(default: f32, stops: Vec<(f32, f32)>) -> Self
Step on zoom: ["step", ["zoom"], default, z0, v0, z1, v1, ...].
Source§impl Expression<[f32; 4]>
impl Expression<[f32; 4]>
Source§impl Expression<bool>
impl Expression<bool>
Trait Implementations§
Source§impl<T: Clone> Clone for Expression<T>
impl<T: Clone> Clone for Expression<T>
Source§fn clone(&self) -> Expression<T>
fn clone(&self) -> Expression<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more