floating_ui/utils_/maybe_from.rs
1use wasm_bindgen::JsValue;
2
3pub trait MaybeFrom<T> {
4 fn maybe_from(value: T) -> Option<Self>
5 where
6 Self: Sized;
7}
8
9impl<T> MaybeFrom<JsValue> for T
10where
11 T: From<JsValue>,
12{
13 fn maybe_from(value: JsValue) -> Option<Self> {
14 if value.is_undefined() {
15 None
16 } else {
17 Some(Self::from(value))
18 }
19 }
20}
21