Skip to content

Commit

Permalink
🩹 zvariant: do not assume RawFd is i32
Browse files Browse the repository at this point in the history
We don't need to assume that `RawFd` is a specific integer type, only
that it is a specific built-in integer type.
  • Loading branch information
Kijewski committed Jul 23, 2023
1 parent b000786 commit 0921a49
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions zvariant/src/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Serialize for Fd {
where
S: Serializer,
{
serializer.serialize_i32(self.0)
self.as_raw_fd().serialize(serializer)
}
}

Expand All @@ -56,7 +56,7 @@ impl<'de> Deserialize<'de> for Fd {
where
D: Deserializer<'de>,
{
Ok(Fd(i32::deserialize(deserializer)?))
Ok(Fd(io::RawFd::deserialize(deserializer)?))
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'de> Deserialize<'de> for OwnedFd {
where
D: Deserializer<'de>,
{
let fd = i32::deserialize(deserializer)?;
let fd = io::RawFd::deserialize(deserializer)?;
let fd = unsafe { io::BorrowedFd::borrow_raw(fd) };
let fd = fd.try_clone_to_owned().map_err(D::Error::custom)?;
Ok(OwnedFd { inner: fd })
Expand Down

0 comments on commit 0921a49

Please sign in to comment.