# MarkupDelegate

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/metadata/struct-markupdelegate/

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

```rust
struct MarkupDelegate
```

An untyped callback (the equivalent of a delegate instance): what an
event subscription declared in metadata receives as its handler, and what
a binding to a method produces.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L110)

## Members

- [`new`](#function-new)
- [`for_method`](#function-for_method)
- [`for_method_of_source`](#function-for_method_of_source)
- [`invoke`](#function-invoke)
- [`try_invoke`](#function-try_invoke)
- [`target`](#function-target)
- [`is_target_alive`](#function-is_target_alive)
- [`method`](#function-method)
- [`declaring_type`](#function-declaring_type)

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

### new

```rust
fn new(f: impl Fn(&[MarkupValue]) -> MarkupValue + 'static) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L116)

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

### for_method

```rust
fn for_method(target: MarkupValue, declaring_type: &'static MarkupType, method: &'static MarkupMethod) -> Self
```

The delegate of a method declared in metadata, bound to `target`
(`method.CreateDelegate(type, target)` in the managed original).
`target` is the instance for an instance method and ignored for a
static one; `declaring_type` is the type whose metadata lists
`method`. The delegate keeps the target alive.

`invoke` calls the method with the arguments given
(after the instance) and discards a failure;
`try_invoke` reports it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L129)

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

### for_method_of_source

```rust
fn for_method_of_source(target: &BoxedValue, declaring_type: &'static MarkupType, method: &'static MarkupMethod) -> Self
```

The delegate of a method of a binding source: what a binding to a
method reads. As `for_method`, but the delegate
does not keep `target` alive (a source that is a reference; a plain
value is held as a binding holds it, by value). Once the target is
gone `target` is `None`,
`is_target_alive` is false and invoking the
delegate does nothing.

Deviation (DEVIATIONS.md, Bindings): the managed delegate has its
target strongly, and so has the command made from it. A template that
binds a command of one of its parts to a method of the templated
control is a cycle there (the control, its template, the part, the
value of its command property, the control), which the collector
frees; without one it would never be freed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L148)

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

### invoke

```rust
fn invoke(self: &Self, arguments: &[MarkupValue]) -> MarkupValue
```

Calls the callback.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L172)

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

### try_invoke

```rust
fn try_invoke(self: &Self, arguments: &[MarkupValue]) -> Result<MarkupValue, MarkupInvokeError>
```

Calls the callback. For the delegate of a declared method
(`for_method`) a failure of the call (wrong
arguments, a failing member) is returned.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L179)

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

### target

```rust
fn target(self: &Self) -> MarkupValue
```

The instance the delegate of a declared instance method is bound to
(the `Target` of the managed original). `None` for a static method
and for a delegate that was not created from a declared method.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L192)

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

### is_target_alive

```rust
fn is_target_alive(self: &Self) -> bool
```

Whether the delegate can still call what it was created for: false
once the target of the delegate of a binding source
(`for_method_of_source`) is gone.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L199)

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

### method

```rust
fn method(self: &Self) -> Option<&'static MarkupMethod>
```

The declared method the delegate was created from (the `Method` of
the managed original), if it was created with
`for_method`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L206)

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

### declaring_type

```rust
fn declaring_type(self: &Self) -> Option<&'static MarkupType>
```

The type whose metadata declares `method`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/metadata/markup_type.rs#L211)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `PartialEq`
- `Debug`
- `Display`

## Availability

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