Add Serialize/Deserialize for std::os::mikros::Errno
Some checks are pending
CI / Test suite (push) Waiting to run
CI / Test suite (windows) (push) Waiting to run
CI / Rust ${{matrix.rust}} (beta) (push) Waiting to run
CI / Rust ${{matrix.rust}} (stable) (push) Waiting to run
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (ubuntu) (push) Waiting to run
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (windows) (push) Waiting to run
CI / Rust ${{matrix.rust}} (1.31.0) (push) Waiting to run
CI / Rust ${{matrix.rust}} (1.34.0) (push) Waiting to run
CI / Rust 1.56.0 (push) Waiting to run
CI / Rust 1.36.0 (push) Waiting to run
CI / Minimal versions (push) Waiting to run
CI / Documentation (push) Waiting to run
CI / Clippy (push) Waiting to run
CI / Miri (push) Waiting to run
CI / Outdated (push) Waiting to run

This commit is contained in:
pjht 2024-10-03 17:59:17 -05:00
parent 31000e1874
commit 7b4c40c037
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
2 changed files with 49 additions and 0 deletions

View File

@ -3181,3 +3181,39 @@ where
s.parse().map_err(Error::custom)
}
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(target_os = "mikros")]
impl<'de> Deserialize<'de> for std::os::mikros::Errno {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_i32(ErrnoVisitor)
}
}
#[cfg(target_os = "mikros")]
struct ErrnoVisitor;
#[cfg(target_os = "mikros")]
impl<'de> Visitor<'de> for ErrnoVisitor {
type Value = std::os::mikros::Errno;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("errno")
}
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
where
E: Error,
{
if let Ok(errno) = Errno::try_from(v) {
Ok(errno)
} else {
Err(E::invalid_value(Unexpected::Signed(v as i32), "errno"))
}
}
}

View File

@ -1094,3 +1094,16 @@ atomic_impl! {
AtomicI64 "64"
AtomicU64 "64"
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(target_os = "mikros")]
impl Serialize for std::os::mikros::Errno {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(self as i32).serialize(serializer)
}
}