Skip to content

Commit c2dafc7

Browse files
alyssaisepilys
authored andcommitted
vhost: impl From<UnixListener> for Listener
It was already possible to do this as follows: unsafe { Listener::from_raw_fd(listener.into_raw_fd()) } This just factors the From implementation out of the FromRawFd implementation so it's possible to do the conversion without an unnecessary unsafe in application code. Signed-off-by: Alyssa Ross <[email protected]>
1 parent fce6393 commit c2dafc7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

vhost/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## [Unreleased]
44

55
### Added
6+
- [[#311]](https://github.com/rust-vmm/vhost/pull/311) Implement
7+
`From<UnixListener>` for `vhost_user::Listener`.
8+
69
### Changed
710
### Deprecated
811
### Fixed

vhost/src/vhost_user/connection.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ impl AsRawFd for Listener {
8686

8787
impl FromRawFd for Listener {
8888
unsafe fn from_raw_fd(fd: RawFd) -> Self {
89-
Listener {
90-
fd: UnixListener::from_raw_fd(fd),
91-
path: None,
92-
}
89+
Self::from(UnixListener::from_raw_fd(fd))
90+
}
91+
}
92+
93+
impl From<UnixListener> for Listener {
94+
fn from(fd: UnixListener) -> Self {
95+
Self { fd, path: None }
9396
}
9497
}
9598

0 commit comments

Comments
 (0)