# BehaviorSubject

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactive/subjects/struct-behaviorsubject/

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

```rust
struct BehaviorSubject<T>
```

A subject that keeps the latest value and hands it to each observer that subscribes, then
every later notification (`BehaviorSubject<T>`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L11)

## Members

- [`new`](#function-new)
- [`value`](#function-value)
- [`try_get_value`](#function-try_get_value)
- [`as_observable`](#function-as_observable)
- [`as_observer`](#function-as_observer)

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

### new

```rust
fn new(value: T) -> Rc<Self>
```

A subject whose value is `value` until it receives one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L26)

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

### value

```rust
fn value(self: &Self) -> Result<T, ObservableError>
```

The latest value (`Value`): the error when the subject ended with one, where upstream
throws it. Panics when the subject has been disposed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L36)

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

### try_get_value

```rust
fn try_get_value(self: &Self) -> Result<Option<T>, ObservableError>
```

The latest value, or `None` once the subject has been disposed (`TryGetValue`); the error
when the subject ended with one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L49)

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

### as_observable

```rust
fn as_observable(self: &Rc<Self>) -> Rc<dyn IObservable<T>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L60)

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

### as_observer

```rust
fn as_observer(self: &Rc<Self>) -> Rc<dyn IObserver<T>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/behavior_subject.rs#L64)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ISubjectHandle<A, B>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-isubjecthandle/)
- [`ISubject<A, B>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-isubject/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`SubscribeGuard<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-subscribeguard/)
- [`IObserver<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-iobserver/)
- [`IObservable<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-iobservable/)
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)
- [`SubjectBase<T>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-subjectbase/)

## Availability

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