Fix Serialize/Deserialize for std::os::mikros::Errno
Some checks failed
CI / Test suite (push) Has been cancelled
CI / Test suite (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (beta) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (stable) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (ubuntu) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.31.0) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.34.0) (push) Has been cancelled
CI / Rust 1.56.0 (push) Has been cancelled
CI / Rust 1.36.0 (push) Has been cancelled
CI / Minimal versions (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Miri (push) Has been cancelled
CI / Outdated (push) Has been cancelled

This commit is contained in:
pjht 2024-10-04 12:33:07 -05:00
parent 7b4c40c037
commit 1b40077a58
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
3 changed files with 26 additions and 16 deletions

2
rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "dev-x86_64-unknown-mikros"

View File

@ -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<A>(self, data: A) -> Result<Self::Value, A::Error>
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<D>(deserializer: D) -> Result<Self, D::Error>
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<OsStr>, 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))
}
}
}

View File

@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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)
}
}