async_component_components/
option.rs

1use std::ops::{Deref, DerefMut};
2
3use async_component_core::AsyncComponent;
4
5#[derive(Debug, Default)]
6pub struct OptionComponent<T>(pub Option<T>);
7
8impl<T> Deref for OptionComponent<T> {
9    type Target = Option<T>;
10
11    fn deref(&self) -> &Self::Target {
12        &self.0
13    }
14}
15
16impl<T> DerefMut for OptionComponent<T> {
17    fn deref_mut(&mut self) -> &mut Self::Target {
18        &mut self.0
19    }
20}
21
22impl<T: AsyncComponent> AsyncComponent for OptionComponent<T> {
23    fn update_component(&mut self) {
24        if let Some(ref mut inner) = self.0 {
25            inner.update_component()
26        }
27    }
28}