1 | #[cfg (unix)] |
2 | pub(crate) const FDS_MAX: usize = 1024; // this is hardcoded in sdbus - nothing in the spec |
3 | |
4 | pub(crate) fn padding_for_8_bytes(value: usize) -> usize { |
5 | padding_for_n_bytes(value, align:8) |
6 | } |
7 | |
8 | pub(crate) fn padding_for_n_bytes(value: usize, align: usize) -> usize { |
9 | let len_rounded_up: usize = value.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1); |
10 | |
11 | len_rounded_up.wrapping_sub(value) |
12 | } |
13 | |
14 | /// Helper trait for macro-generated code. |
15 | /// |
16 | /// This trait allows macros to refer to the `Ok` and `Err` types of a [Result] that is behind a |
17 | /// type alias. This is currently required because the macros for properties expect a Result |
18 | /// return value, but the macro-generated `receive_` functions need to refer to the actual |
19 | /// type without the associated error. |
20 | pub trait ResultAdapter { |
21 | type Ok; |
22 | type Err; |
23 | } |
24 | |
25 | impl<T, E> ResultAdapter for Result<T, E> { |
26 | type Ok = T; |
27 | type Err = E; |
28 | } |
29 | |
30 | #[cfg (not(feature = "tokio" ))] |
31 | #[doc (hidden)] |
32 | pub fn block_on<F: std::future::Future>(future: F) -> F::Output { |
33 | async_io::block_on(future) |
34 | } |
35 | |
36 | #[cfg (feature = "tokio" )] |
37 | #[doc (hidden)] |
38 | pub fn block_on<F: std::future::Future>(future: F) -> F::Output { |
39 | static TOKIO_RT: once_cell::sync::Lazy<tokio::runtime::Runtime> = |
40 | once_cell::sync::Lazy::new(|| { |
41 | tokio::runtime::Builder::new_current_thread() |
42 | .enable_io() |
43 | .enable_time() |
44 | .build() |
45 | .expect("launch of single-threaded tokio runtime" ) |
46 | }); |
47 | TOKIO_RT.block_on(future) |
48 | } |
49 | |