Skip to content

Commit a9981b0

Browse files
committed
add wasm-bindgen conversion impls to Datetime
1 parent ebc808e commit a9981b0

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/datetime/mod.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,74 @@ impl From<DateTime<Utc>> for js_sys::Date {
19651965
}
19661966
}
19671967

1968+
#[cfg(all(
1969+
target_arch = "wasm32",
1970+
feature = "wasmbind",
1971+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
1972+
))]
1973+
impl wasm_bindgen::convert::FromWasmAbi for DateTime<Utc> {
1974+
type Abi = <js_sys::Date as wasm_bindgen::convert::FromWasmAbi>::Abi;
1975+
unsafe fn from_abi(js: Self::Abi) -> Self {
1976+
unsafe { js_sys::Date::from_abi(js).into() }
1977+
}
1978+
}
1979+
1980+
#[cfg(all(
1981+
target_arch = "wasm32",
1982+
feature = "wasmbind",
1983+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
1984+
))]
1985+
impl wasm_bindgen::convert::IntoWasmAbi for DateTime<Utc> {
1986+
type Abi = <js_sys::Date as wasm_bindgen::convert::IntoWasmAbi>::Abi;
1987+
fn into_abi(self) -> Self::Abi {
1988+
js_sys::Date::from(self).into_abi()
1989+
}
1990+
}
1991+
1992+
#[cfg(all(
1993+
target_arch = "wasm32",
1994+
feature = "wasmbind",
1995+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
1996+
))]
1997+
impl wasm_bindgen::describe::WasmDescribe for DateTime<Utc> {
1998+
fn describe() {
1999+
js_sys::Date::describe()
2000+
}
2001+
}
2002+
2003+
#[cfg(all(
2004+
target_arch = "wasm32",
2005+
feature = "wasmbind",
2006+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
2007+
))]
2008+
impl wasm_bindgen::describe::WasmDescribeVector for DateTime<Utc> {
2009+
fn describe_vector() {
2010+
js_sys::Date::describe_vector()
2011+
}
2012+
}
2013+
2014+
#[cfg(all(
2015+
target_arch = "wasm32",
2016+
feature = "wasmbind",
2017+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
2018+
))]
2019+
impl wasm_bindgen::convert::OptionFromWasmAbi for DateTime<Utc> {
2020+
fn is_none(abi: &Self::Abi) -> bool {
2021+
js_sys::Date::is_none(abi)
2022+
}
2023+
}
2024+
2025+
#[cfg(all(
2026+
target_arch = "wasm32",
2027+
feature = "wasmbind",
2028+
not(any(target_os = "emscripten", target_os = "wasi", target_os = "linux"))
2029+
))]
2030+
impl wasm_bindgen::convert::OptionIntoWasmAbi for DateTime<Utc> {
2031+
fn none() -> Self::Abi {
2032+
js_sys::Date::none()
2033+
}
2034+
}
2035+
19682036
// Note that implementation of Arbitrary cannot be simply derived for DateTime<Tz>, due to
19692037
// the nontrivial bound <Tz as TimeZone>::Offset: Arbitrary.
19702038
#[cfg(all(feature = "arbitrary", feature = "std"))]

0 commit comments

Comments
 (0)