-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-gate custom transports behind
any_transport
feature
- Loading branch information
1 parent
adb1908
commit eaec63e
Showing
4 changed files
with
100 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::any::Any; | ||
use std::collections::VecDeque; | ||
use std::io; | ||
use std::os::fd::{OwnedFd, RawFd}; | ||
|
||
use wayrs_core::transport::Transport; | ||
use wayrs_core::IoMode; | ||
|
||
pub struct AnyTranpsort(Box<dyn AnyTransportImp>); | ||
|
||
impl AnyTranpsort { | ||
pub fn new<T>(transport: T) -> Self | ||
where | ||
T: Transport + Send + 'static, | ||
{ | ||
Self(Box::new(transport)) | ||
} | ||
|
||
pub fn as_any(&self) -> &dyn Any { | ||
self.0.as_any() | ||
} | ||
|
||
pub fn as_any_mut(&mut self) -> &mut dyn Any { | ||
self.0.as_any_mut() | ||
} | ||
} | ||
|
||
trait AnyTransportImp: Transport + Send { | ||
fn as_any(&self) -> &dyn Any; | ||
fn as_any_mut(&mut self) -> &mut dyn Any; | ||
} | ||
|
||
impl<T: Transport + Send + 'static> AnyTransportImp for T { | ||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
fn as_any_mut(&mut self) -> &mut dyn Any { | ||
self | ||
} | ||
} | ||
|
||
impl Transport for AnyTranpsort { | ||
fn pollable_fd(&self) -> RawFd { | ||
self.0.as_ref().pollable_fd() | ||
} | ||
|
||
fn send(&mut self, bytes: &[io::IoSlice], fds: &[OwnedFd], mode: IoMode) -> io::Result<usize> { | ||
self.0.as_mut().send(bytes, fds, mode) | ||
} | ||
|
||
fn recv( | ||
&mut self, | ||
bytes: &mut [io::IoSliceMut], | ||
fds: &mut VecDeque<OwnedFd>, | ||
mode: IoMode, | ||
) -> io::Result<usize> { | ||
self.0.as_mut().recv(bytes, fds, mode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters