Skip to main content

Module converters

Module converters 

Source
Expand description

Rust value converters for data binding.

A Converter wraps a Noesis::BaseValueConverter subclass whose TryConvert / TryConvertBack forward into a Rust ValueConverter. This is what real bindings need: mapping a source value to a target-shaped value (bool → text/Visibility, number formatting, enum mapping, …) as the data crosses the binding.

Binding values cross the FFI as boxed Noesis::BaseComponent*. The callback receives the source value and the optional ConverterParameter as ConvertArgs (unbox them with ConvertArg::as_i32 / as_bool / as_f64 / as_str), and returns a Converted the trampoline re-boxes for Noesis (or None to signal UnsetValue, so the binding falls back to its FallbackValue / the property default).

§Reaching a binding

Two ways, both wired the same on the C++ side:

  • Code-built binding, the primary path for Rust integration: Binding::new("Path").converter(&converter) then set_binding. See crate::binding.
  • XAML resource: insert the converter into an element’s ResourceDictionary with add_resource and author {Binding Path, Converter={StaticResource Key}} in XAML.

§Lifetime

Converter holds the caller’s +1 reference, released on drop. If a binding still references the converter (the common case while it’s wired onto a live element), the underlying object (and the boxed handler) stay alive until that reference also drops. The handler is freed exactly once, by the C++ destructor, after the last reference goes away.

§Threading

convert / convert_back fire from inside Noesis’s binding pump on whatever thread drives the view. The handler is stored behind Send; keep the work small.

Structs§

ConvertArg
A borrowed, boxed binding value handed to a ValueConverter. None-valued (the bound source produced null / the control supplied no parameter) reports is_none; the typed accessors return None when the boxed runtime type doesn’t match.
Converter
A Rust-backed IValueConverter. Owns a +1 reference released on drop. Attach it to a binding with Binding::converter, or insert it into an element’s resources with add_resource.

Enums§

Converted
A value a ValueConverter produces. The trampoline re-boxes it into the Noesis::BaseComponent* the binding engine expects.

Traits§

ValueConverter
Rust-side conversion logic. convert maps a binding source value to the target; convert_back (only reached on a TwoWay / OneWayToSource binding) maps a target value back to the source. Returning None signals UnsetValue.