# IValidationRule

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-xaml-interactions-custom/trait-ivalidationrule/

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

```rust
trait IValidationRule
```

Defines a validation rule.

Deviation (DEVIATIONS.md, Behaviors): the reference contract is generic over the type of the
validated value (`IValidationRule<in T>`); here the value is untyped (the value of the
validated property, null when the property holds no value), and a rule that expects another
type of value does not validate it. The rules are objects of the class model, so a class states
that it implements the contract in its static constructor
(`<dyn IValidationRule>::register::<MyRule>()`), and the contract finds the implementation of
an object through its runtime type (`<dyn IValidationRule>::of(object)`), as the contracts of
the interactivity crate do.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactions.Custom/validation/contract/i_validation_rule.rs#L16)

## Members

- [`error_message`](#function-error_message)
- [`set_error_message`](#function-set_error_message)
- [`validate`](#function-validate)

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

### error_message

```rust
fn error_message(self: &Self) -> Option<String>
```

Gets the error message for failed validation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactions.Custom/validation/contract/i_validation_rule.rs#L18)

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

### set_error_message

```rust
fn set_error_message(self: &Self, value: Option<String>)
```

Sets the error message for failed validation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactions.Custom/validation/contract/i_validation_rule.rs#L21)

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

### validate

```rust
fn validate(self: &Self, value: Option<&BoxedValue>) -> bool
```

Validates the specified value (null when the property holds no value).

Returns `true` if value is valid.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactions.Custom/validation/contract/i_validation_rule.rs#L26)

## Trait implementations

- [`IValidationRule`](/docs/0.5.0/api/ferroui-xaml-interactions-custom/trait-ivalidationrule/)

## Availability

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