floating_ui/utils_/
mod.rs1mod string_union;
2pub(crate) use string_union::string_union;
3pub use string_union::StringUnion;
4
5mod enum_union;
6pub(crate) use enum_union::enum_union;
7
8mod index;
9pub(crate) use index::index;
10
11mod key_in;
12pub(crate) use key_in::key_in;
13
14mod extends;
15pub(crate) use extends::extends;
16use wasm_bindgen::JsValue;
17
18pub mod object_utils;
19
20mod maybe_from;
21pub use maybe_from::MaybeFrom;
22
23pub trait TryMaybeFrom<T> {
24 type Error;
25
26 fn try_maybe_from(value: T) -> Result<Option<Self>, Self::Error>
27 where
28 Self: Sized;
29}
30
31impl<T, E> TryMaybeFrom<JsValue> for T
32where
33 T: TryFrom<JsValue, Error = E>,
34{
35 type Error = E;
36
37 fn try_maybe_from(value: JsValue) -> Result<Option<Self>, Self::Error>
38 where
39 Self: Sized,
40 {
41 if value.is_undefined() {
42 return Ok(None);
43 }
44
45 Ok(Some(Self::try_from(value)?))
46 }
47}