Skip to main content

Expression

Enum Expression 

Source
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

§key: String

Feature-state key to look up (e.g. "hover", "selected").

§fallback: T

Default 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

§key: String

Property key to read from feature properties.

§fallback: T

Value 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).

§stops: Vec<(f32, T)>

Ordered stop pairs (input_value, output_value).

§

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: T

Default value when input is below all stops.

§stops: Vec<(f32, T)>

Ordered stops (threshold, output_value).

§

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.

§cases: Vec<(String, T)>

Cases: (label, output_value).

§fallback: T

Value 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: T

Value 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>

Source

pub fn evaluate(&self) -> T

Evaluate with no context (uses defaults).

Source

pub fn evaluate_with_context(&self, ctx: StyleEvalContext) -> T

Evaluate with a zoom-only legacy context.

Source

pub fn evaluate_with_full_context(&self, ctx: &StyleEvalContextFull<'_>) -> T

Evaluate with a full legacy context (zoom + feature state).

Source

pub fn evaluate_with_properties(&self, ctx: &ExprEvalContext<'_>) -> T

Evaluate with feature properties for data-driven styling.

Source

pub fn eval_full(&self, ctx: &ExprEvalContext<'_>) -> T

Core evaluation entry point.

Source§

impl<T> Expression<T>

Source

pub fn feature_state_key(key: impl Into<String>, fallback: T) -> Self

Create a feature-state-driven expression.

Source

pub fn is_feature_state_driven(&self) -> bool

Whether this expression depends on per-feature mutable state.

Source

pub fn is_data_driven(&self) -> bool

Whether this expression depends on feature properties.

Source§

impl Expression<f32>

Source

pub fn zoom_interpolate(stops: Vec<(f32, f32)>) -> Self

Interpolate linearly on zoom: ["interpolate", ["linear"], ["zoom"], z0, v0, z1, v1, ...].

Source

pub fn zoom_step(default: f32, stops: Vec<(f32, f32)>) -> Self

Step on zoom: ["step", ["zoom"], default, z0, v0, z1, v1, ...].

Source

pub fn property(key: impl Into<String>, fallback: f32) -> Self

Read a numeric property with fallback.

Source

pub fn property_interpolate( property: impl Into<String>, fallback: f64, stops: Vec<(f32, f32)>, ) -> Self

Interpolate linearly on a numeric feature property.

Source§

impl Expression<[f32; 4]>

Source

pub fn zoom_interpolate(stops: Vec<(f32, [f32; 4])>) -> Self

Interpolate colors linearly on zoom.

Source

pub fn zoom_step(default: [f32; 4], stops: Vec<(f32, [f32; 4])>) -> Self

Step on zoom for colors.

Source

pub fn property_match( property: impl Into<String>, cases: Vec<(String, [f32; 4])>, fallback: [f32; 4], ) -> Self

Match a string property to a color.

Source§

impl Expression<bool>

Source

pub fn property(key: impl Into<String>, fallback: bool) -> Self

Read a boolean feature property.

Source§

impl Expression<String>

Source

pub fn property(key: impl Into<String>, fallback: impl Into<String>) -> Self

Read a string feature property.

Trait Implementations§

Source§

impl<T: Clone> Clone for Expression<T>

Source§

fn clone(&self) -> Expression<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Expression<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Debug> Display for Expression<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<T> for Expression<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for Expression<T>

Source§

fn eq(&self, other: &Expression<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Expression<T>

Auto Trait Implementations§

§

impl<T> Freeze for Expression<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Expression<T>
where T: RefUnwindSafe,

§

impl<T> Send for Expression<T>
where T: Send,

§

impl<T> Sync for Expression<T>
where T: Sync,

§

impl<T> Unpin for Expression<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Expression<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Expression<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.