Add empty structs for unix to bring lessen the amount of platfrom specific code users have to write

This commit is contained in:
Emīls Piņķis 2018-08-25 00:22:36 +01:00
parent a2dc227fe4
commit c9322e22c3
2 changed files with 16 additions and 3 deletions

View File

@ -32,9 +32,16 @@ use tokio_named_pipes::NamedPipe;
#[cfg(windows)]
mod win_permissions;
#[cfg(windows)]
pub use win_permissions::SecurityAttributes;
#[cfg(unix)]
mod unix_permissions;
#[cfg(unix)]
pub use unix_permissions::SecurityAttributes;
/// For testing/examples
@ -75,7 +82,6 @@ pub fn dummy_endpoint() -> String {
/// ```
pub struct Endpoint {
path: String,
#[cfg(windows)]
security_attributes: SecurityAttributes,
}
@ -123,7 +129,6 @@ impl Endpoint {
tokio_uds::UnixListener::bind(&self.path, handle)
}
#[cfg(windows)]
pub fn set_security_attributes(&mut self, security_attributes: SecurityAttributes) {
self.security_attributes = security_attributes;
}
@ -138,7 +143,6 @@ impl Endpoint {
pub fn new(path: String) -> Self {
Endpoint {
path: path,
#[cfg(windows)]
security_attributes: SecurityAttributes::empty(),
}
}

9
src/unix_permissions.rs Normal file
View File

@ -0,0 +1,9 @@
/// A NOOP struct for bringing the API between Windows and Unix up to parity. To set permissions
/// properly on Unix, you can just use `std::os::unix::fs::PermissionsExt`.
pub struct SecurityAttributes {}
impl SecurityAttributes {
pub fn empty() -> Self {Self{}}
pub fn allow_everyone_connect() -> Self {Self{}}
pub fn allow_everyone_create() -> Self {Self{}}
}