# BindingTypeConverter

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/binding/bindings/trait-bindingtypeconverter/

**trait** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
trait BindingTypeConverter: 'static
```

The base of the typed converters (`BindingTypeConverter<TFrom, TTo>`): a converter implements
its typed conversion and its affinity, and the blanket implementations write
[`IBindingTypeConverter`](/docs/0.5.0/api/ferroui-reactiveui/binding/bindings/trait-ibindingtypeconverter/) (the source and target types, the type-erased conversion) and
`IBindingTypeConverterOf<From, To>` from them.

```
use ferroui_reactiveui::{BindingTypeConverter, IBindingTypeConverter, IBindingTypeConverterOf};
use std::any::Any;

struct Doubler;

impl BindingTypeConverter for Doubler {
    type From = i32;
    type To = i64;

    fn affinity(&self) -> i32 {
        1
    }

    fn convert(&self, from: Option<&i32>, _conversion_hint: Option<&dyn Any>) -> Option<i64> {
        Some(i64::from(*from?) * 2)
    }
}

assert_eq!(Doubler.try_convert(Some(&21), None), Some(42));
let converted = Doubler.try_convert_typed(Some(&21), None).unwrap();
assert_eq!(converted.downcast_ref::<i64>(), Some(&42));
assert!(Doubler.try_convert_typed(Some(&"21"), None).is_none());
```

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/bindings/binding_type_converter.rs#L41)

## Members

- [`From`](#assoc_type-from)
- [`To`](#assoc_type-to)
- [`affinity`](#function-affinity)
- [`convert`](#function-convert)

<a id="assoc_type-from"></a>

### From

```rust
type From: 'static
```

The type converted from (`TFrom`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/bindings/binding_type_converter.rs#L43)

<a id="assoc_type-to"></a>

### To

```rust
type To: 'static
```

The type converted to (`TTo`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/bindings/binding_type_converter.rs#L46)

<a id="function-affinity"></a>

### affinity

```rust
fn affinity(self: &Self) -> i32
```

The affinity of the converter (`GetAffinityForObjects`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/bindings/binding_type_converter.rs#L49)

<a id="function-convert"></a>

### convert

```rust
fn convert(self: &Self, from: Option<&<Self as >::From>, conversion_hint: Option<&dyn Any>) -> Option<<Self as >::To>
```

Converts `from` (`None` for upstream's `null`), with an optional `conversion_hint`; `None`
when the conversion fails (`TryConvert`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/bindings/binding_type_converter.rs#L53)

## Trait implementations

- [`BindingTypeConverter`](/docs/0.5.0/api/ferroui-reactiveui/binding/bindings/trait-bindingtypeconverter/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
