1#[cfg(unix)]
2pub(crate) const FDS_MAX: usize = 1024; pub(crate) fn padding_for_8_bytes(value: usize) -> usize {
5 padding_for_n_bytes(value, 8)
6}
7
8pub(crate) fn padding_for_n_bytes(value: usize, align: usize) -> usize {
9 let len_rounded_up = value.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1);
10
11 len_rounded_up.wrapping_sub(value)
12}
13
14#[doc(hidden)]
21pub trait ResultAdapter {
22 type Ok;
23 type Err;
24}
25
26impl<T, E> ResultAdapter for Result<T, E> {
27 type Ok = T;
28 type Err = E;
29}
30
31#[cfg(not(feature = "tokio"))]
32#[doc(hidden)]
33pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
34 async_io::block_on(future)
35}
36
37#[cfg(feature = "tokio")]
38#[doc(hidden)]
39pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
40 use std::sync::OnceLock;
41 static TOKIO_RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
42 let runtime = TOKIO_RT.get_or_init(|| {
43 tokio::runtime::Builder::new_current_thread()
44 .enable_io()
45 .enable_time()
46 .build()
47 .expect("launch of single-threaded tokio runtime")
48 });
49 runtime.block_on(future)
50}
51
52pub(crate) fn is_flatpak() -> bool {
54 std::env::var("FLATPAK_ID").is_ok()
55}