# SubscribeGuard

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-system/trait-subscribeguard/

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

```rust
trait SubscribeGuard<T>
```

Subscribes and returns the [`Subscription`](/docs/0.5.0/api/ferroui-system/struct-subscription/) guard instead of the handle (C3b of #423,
`docs/idiomatic-rust-disposal.md`, step D5).

`IObservable::subscribe` keeps returning the `Rc<dyn IDisposable>` of the Rx contract, which
the operators compose and which keeps the subscription alive when it is dropped. An owner that
keeps a subscription only to end it later subscribes with
`subscribe_guard` and holds the guard: dropping it
unsubscribes, once, and `Subscription::detach` gives the handle back where the subscription
is meant to last as long as its source.

The trait is implemented for every observable, sized or not, so it applies to a concrete
observable, to `dyn IObservable<T>` and, through deref, to `Rc<dyn IObservable<T>>`.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/i_observable.rs#L36)

## Members

- [`subscribe_guard`](#function-subscribe_guard)

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

### subscribe_guard

```rust
fn subscribe_guard(self: &Self, observer: Rc<dyn IObserver<T>>) -> Subscription
```

Subscribes `observer`; dropping the returned guard unsubscribes it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/i_observable.rs#L38)

## Trait implementations

- [`SubscribeGuard<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-subscribeguard/)

## Availability

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