From 1b40077a58d272091a641d62e57a92867d2bbf23 Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 4 Oct 2024 12:33:07 -0500 Subject: [PATCH] Fix Serialize/Deserialize for std::os::mikros::Errno --- rust-toolchain.toml | 2 ++ serde/src/de/impls.rs | 24 ++++++++++++++---------- serde/src/ser/impls.rs | 16 ++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..a5535e34 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "dev-x86_64-unknown-mikros" diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 99a2d5d0..7dd5c61c 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -1898,17 +1898,17 @@ forwarded_impl! { // // #[derive(Deserialize)] // #[serde(variant_identifier)] -#[cfg(all(feature = "std", any(unix, windows)))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] variant_identifier! { OsStringKind (Unix; b"Unix"; 0, Windows; b"Windows"; 1) "`Unix` or `Windows`", OSSTR_VARIANTS } -#[cfg(all(feature = "std", any(unix, windows)))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] struct OsStringVisitor; -#[cfg(all(feature = "std", any(unix, windows)))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] impl<'de> Visitor<'de> for OsStringVisitor { type Value = OsString; @@ -1916,12 +1916,15 @@ impl<'de> Visitor<'de> for OsStringVisitor { formatter.write_str("os string") } - #[cfg(unix)] + #[cfg(any(unix, target_os = "mikros"))] fn visit_enum(self, data: A) -> Result where A: EnumAccess<'de>, { + #[cfg(unix)] use std::os::unix::ffi::OsStringExt; + #[cfg(target_os = "mikros")] + use std::os::mikros::ffi::OsStringExt; match tri!(data.variant()) { (OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec), @@ -1949,8 +1952,8 @@ impl<'de> Visitor<'de> for OsStringVisitor { } } -#[cfg(all(feature = "std", any(unix, windows)))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))))] impl<'de> Deserialize<'de> for OsString { fn deserialize(deserializer: D) -> Result where @@ -1981,8 +1984,8 @@ forwarded_impl! { } forwarded_impl! { - #[cfg(all(feature = "std", any(unix, windows)))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))] + #[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] + #[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))))] (), Box, OsString::into_boxed_os_str } @@ -3210,10 +3213,11 @@ impl<'de> Visitor<'de> for ErrnoVisitor { where E: Error, { - if let Ok(errno) = Errno::try_from(v) { + use std::convert::TryFrom; + if let Ok(errno) = std::os::mikros::Errno::try_from(v) { Ok(errno) } else { - Err(E::invalid_value(Unexpected::Signed(v as i32), "errno")) + Err(E::invalid_value(Unexpected::Signed(v as i64), &self)) } } } diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 801ea0cb..bb3e27b4 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -979,15 +979,19 @@ impl Serialize for PathBuf { } } -#[cfg(all(feature = "std", any(unix, windows)))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))))] impl Serialize for OsStr { - #[cfg(unix)] + #[cfg(any(unix, target_os = "mikros"))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { + + #[cfg(unix)] use std::os::unix::ffi::OsStrExt; + #[cfg(target_os = "mikros")] + use std::os::mikros::ffi::OsStrExt; serializer.serialize_newtype_variant("OsString", 0, "Unix", self.as_bytes()) } @@ -1002,8 +1006,8 @@ impl Serialize for OsStr { } } -#[cfg(all(feature = "std", any(unix, windows)))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))] +#[cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows, target_os = "mikros")))))] impl Serialize for OsString { fn serialize(&self, serializer: S) -> Result where @@ -1104,6 +1108,6 @@ impl Serialize for std::os::mikros::Errno { where S: Serializer, { - (self as i32).serialize(serializer) + (*self as i32).serialize(serializer) } }