Skip to content

Commit

Permalink
Implement RefArg for io-lifetimes::OwnedFd
Browse files Browse the repository at this point in the history
  • Loading branch information
diwic committed Dec 30, 2022
1 parent a7df6c1 commit 32272f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ Features

The `futures` feature makes `dbus` depend on the `futures` crate. This enables the `nonblock` module (used by the `dbus-tokio` crate).

The `no-string-validation` feature skips an extra check that a specific string (e g a `Path`, `ErrorName` etc) conforms to the D-Bus specification, which might also make things a tiny bit faster. But - if you do so, and then actually send invalid strings to the D-Bus library, you might get a panic instead of a proper error.

The `vendored` feature links libdbus statically into the final executable.

The `io-lifetimes` feature adds a dependency on the `io-lifetimes` crate, enabling you to append and get std's `OwnedFd`.

The `no-string-validation` feature skips an extra check that a specific string (e g a `Path`, `ErrorName` etc) conforms to the D-Bus specification, which might also make things a tiny bit faster. But - if you do so, and then actually send invalid strings to the D-Bus library, you might get a panic instead of a proper error.

Requirements
============

Expand Down
20 changes: 20 additions & 0 deletions dbus/src/arg/basic_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl<'a> Get<'a> for io_lifetimes::OwnedFd {
}
}


#[cfg(unix)]
refarg_impl!(OwnedFd, _i, { use std::os::unix::io::AsRawFd; Some(_i.as_raw_fd() as i64) }, None, None, None);

Expand Down Expand Up @@ -321,6 +322,25 @@ impl RefArg for File {
fn box_clone(&self) -> Box<dyn RefArg + 'static> { Box::new(self.try_clone().unwrap()) }
}

#[cfg(all(unix, feature = "io-lifetimes"))]
impl RefArg for io_lifetimes::OwnedFd {
#[inline]
fn arg_type(&self) -> ArgType { <Self as Arg>::ARG_TYPE }
#[inline]
fn signature(&self) -> Signature<'static> { <Self as Arg>::signature() }
#[inline]
fn append(&self, i: &mut IterAppend) { <Self as Append>::append_by_ref(self, i) }
#[inline]
fn as_any(&self) -> &dyn any::Any { self }
#[inline]
fn as_any_mut(&mut self) -> &mut dyn any::Any { self }
#[cfg(unix)]
#[inline]
fn as_i64(&self) -> Option<i64> { Some(self.as_raw_fd() as i64) }
#[inline]
fn box_clone(&self) -> Box<dyn RefArg + 'static> { Box::new(self.try_clone().unwrap()) }
}


macro_rules! string_impl {
($t: ident, $s: ident, $f: expr) => {
Expand Down

0 comments on commit 32272f8

Please sign in to comment.