278 lines
7.7 KiB
Rust
Raw Normal View History

2023-09-01 21:13:05 -04:00
//! # Veilid Tools
//!
2023-08-28 10:32:55 -05:00
//! A collection of baseline tools for Rust development use by Veilid and Veilid-enabled Rust applications
//!
//! These are used by `veilid-core`, `veilid-server`, `veilid-cli` and may be used by any other applications
//! that link in `veilid-core` if a common baseline of functionality is desired. Extending this crate with new
//! utility functions is encouraged rather than adding 'common' functionality to `veilid-core`, allowing it to
//! remain free of boilerplate and utility classes that could be reused elsewhere.
//!
//! Everything added to this crate must be extensively unit-tested.
2023-09-01 21:13:05 -04:00
//!
//! ## Features
//!
//! The default `veilid-tools` configurations are:
//!
//! * `default` - Uses `tokio` as the async runtime
//!
//! If you use `--no-default-features`, you can switch to other runtimes:
//!
//! * `rt-async-std` - Uses `async-std` as the async runtime
//! * `rt-wasm-bindgen` - When building for the `wasm32` architecture, use this to enable `wasm-bindgen-futures` as the async runtime
//!
2023-09-17 19:37:02 -04:00
#![deny(clippy::all)]
#![allow(clippy::comparison_chain, clippy::upper_case_acronyms)]
#![deny(unused_must_use)]
2023-08-28 10:32:55 -05:00
pub mod assembly_buffer;
pub mod async_peek_stream;
pub mod async_tag_lock;
pub mod clone_stream;
pub mod deferred_stream_processor;
2024-10-23 23:27:34 +00:00
pub mod event_bus;
2023-08-28 10:32:55 -05:00
pub mod eventual;
pub mod eventual_base;
pub mod eventual_value;
pub mod eventual_value_clone;
2024-10-11 00:16:39 +00:00
pub mod future_queue;
2023-08-28 10:32:55 -05:00
pub mod interval;
pub mod ip_addr_port;
pub mod ip_extra;
2023-12-14 17:23:43 -05:00
pub mod ipc;
2023-08-28 10:32:55 -05:00
pub mod must_join_handle;
pub mod must_join_single_future;
pub mod mutable_future;
2023-10-13 17:57:38 -04:00
pub mod network_interfaces;
2023-08-28 10:32:55 -05:00
pub mod network_result;
pub mod random;
pub mod single_shot_eventual;
pub mod sleep;
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub mod socket_tools;
2023-08-28 10:32:55 -05:00
pub mod spawn;
pub mod split_url;
2024-07-19 13:00:15 -04:00
pub mod startup_lock;
pub mod static_string_table;
2023-08-28 10:32:55 -05:00
pub mod tick_task;
pub mod timeout;
pub mod timeout_or;
pub mod timestamp;
pub mod tools;
#[cfg(feature = "virtual-network")]
pub mod virtual_network;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
2023-08-28 10:32:55 -05:00
pub mod wasm;
2021-11-22 11:28:30 -05:00
pub type PinBox<T> = Pin<Box<T>>;
pub type PinBoxFuture<T> = PinBox<dyn Future<Output = T> + 'static>;
pub type PinBoxFutureLifetime<'a, T> = PinBox<dyn Future<Output = T> + 'a>;
pub type SendPinBoxFuture<T> = PinBox<dyn Future<Output = T> + Send + 'static>;
pub type SendPinBoxFutureLifetime<'a, T> = PinBox<dyn Future<Output = T> + Send + 'a>;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::borrow::{Cow, ToOwned};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::boxed::Box;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::cell::RefCell;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::cmp;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::btree_map::BTreeMap;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::btree_set::BTreeSet;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::hash_map::HashMap;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::hash_set::HashSet;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::LinkedList;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::collections::VecDeque;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::convert::{TryFrom, TryInto};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::fmt;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::future::Future;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::mem;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-26 14:16:02 -05:00
pub use std::net::{
IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs,
};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::ops::{Fn, FnMut, FnOnce};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::pin::Pin;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::rc::Rc;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-27 09:00:20 -05:00
pub use std::str::FromStr;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-26 22:18:55 -05:00
pub use std::string::{String, ToString};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2024-07-20 18:05:24 -04:00
pub use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::sync::{Arc, Weak};
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::task;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::time::Duration;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-11-06 16:07:56 -05:00
pub use std::vec::Vec;
2024-07-20 18:05:24 -04:00
#[doc(no_inline)]
pub use async_lock::RwLock as AsyncRwLock;
#[doc(no_inline)]
pub use async_lock::RwLockReadGuard as AsyncRwLockReadGuard;
#[doc(no_inline)]
pub use async_lock::RwLockReadGuardArc as AsyncRwLockReadGuardArc;
#[doc(no_inline)]
2024-07-20 18:05:24 -04:00
pub use async_lock::RwLockWriteGuard as AsyncRwLockWriteGuard;
#[doc(no_inline)]
pub use async_lock::RwLockWriteGuardArc as AsyncRwLockWriteGuardArc;
2024-07-20 18:05:24 -04:00
2021-11-22 11:28:30 -05:00
cfg_if! {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-01-03 23:58:26 -05:00
pub use async_lock::Mutex as AsyncMutex;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-01-03 23:58:26 -05:00
pub use async_lock::MutexGuard as AsyncMutexGuard;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-10-02 18:47:36 -04:00
pub use async_lock::MutexGuardArc as AsyncMutexGuardArc;
2024-07-19 13:00:15 -04:00
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use async_executors::JoinHandle as LowLevelJoinHandle;
2024-07-19 13:00:15 -04:00
2021-11-22 11:28:30 -05:00
} else {
2022-06-27 23:46:29 -04:00
cfg_if! {
if #[cfg(feature="rt-async-std")] {
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use async_std::sync::Mutex as AsyncMutex;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use async_std::sync::MutexGuard as AsyncMutexGuard;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-10-02 18:47:36 -04:00
pub use async_std::sync::MutexGuardArc as AsyncMutexGuardArc;
2024-07-19 13:00:15 -04:00
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use async_std::task::JoinHandle as LowLevelJoinHandle;
2024-07-19 13:00:15 -04:00
2022-06-27 23:46:29 -04:00
} else if #[cfg(feature="rt-tokio")] {
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use tokio::sync::Mutex as AsyncMutex;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use tokio::sync::MutexGuard as AsyncMutexGuard;
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-10-02 18:47:36 -04:00
pub use tokio::sync::OwnedMutexGuard as AsyncMutexGuardArc;
2024-07-19 13:00:15 -04:00
2023-08-28 10:32:55 -05:00
#[doc(no_inline)]
2022-06-27 23:46:29 -04:00
pub use tokio::task::JoinHandle as LowLevelJoinHandle;
2022-08-22 13:27:26 -04:00
} else {
2024-08-11 09:43:37 -07:00
compile_error!("needs executor implementation");
2022-06-27 23:46:29 -04:00
}
}
2021-11-22 11:28:30 -05:00
}
}
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2023-06-23 12:05:28 -04:00
pub use assembly_buffer::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-01-05 12:01:02 -05:00
pub use async_peek_stream::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-10-02 18:47:36 -04:00
pub use async_tag_lock::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-01-05 12:01:02 -05:00
pub use clone_stream::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
pub use deferred_stream_processor::*;
#[doc(inline)]
2024-10-23 23:27:34 +00:00
pub use event_bus::*;
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use eventual::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use eventual_base::{EventualCommon, EventualResolvedFuture};
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use eventual_value::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use eventual_value_clone::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2024-10-11 00:16:39 +00:00
pub use future_queue::*;
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use interval::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use ip_addr_port::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use ip_extra::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2023-12-14 17:23:43 -05:00
pub use ipc::*;
#[doc(inline)]
2022-06-12 20:58:02 -04:00
pub use must_join_handle::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-06-12 20:58:02 -04:00
pub use must_join_single_future::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-06-04 20:18:26 -04:00
pub use mutable_future::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2023-10-13 17:57:38 -04:00
pub use network_interfaces::*;
#[doc(inline)]
2022-07-14 16:57:34 -04:00
pub use network_result::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use random::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use single_shot_eventual::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use sleep::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use socket_tools::*;
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use spawn::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2023-06-08 14:07:09 -04:00
pub use split_url::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2024-07-19 13:00:15 -04:00
pub use startup_lock::*;
#[doc(inline)]
pub use static_string_table::*;
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use tick_task::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use timeout::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-07-10 17:36:50 -04:00
pub use timeout_or::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2022-11-26 21:37:23 -05:00
pub use timestamp::*;
2023-08-28 10:32:55 -05:00
#[doc(inline)]
2021-11-22 11:28:30 -05:00
pub use tools::*;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
2022-11-26 21:37:23 -05:00
pub use wasm::*;
2022-11-27 09:00:20 -05:00
// Tests must be public for wasm-pack tests
pub mod tests;
2022-11-27 22:33:41 -05:00
2023-06-08 14:07:09 -04:00
cfg_if! {
if #[cfg(feature = "tracing")] {
use tracing::*;
2024-03-07 16:49:59 -05:00
#[macro_export]
macro_rules! debug_target_enabled {
($target:expr) => { enabled!(target: $target, Level::DEBUG) }
}
2023-06-08 14:07:09 -04:00
} else {
use log::*;
2024-03-07 16:49:59 -05:00
#[macro_export]
macro_rules! debug_target_enabled {
($target:expr) => { log_enabled!(target: $target, Level::Debug) }
}
2023-06-08 14:07:09 -04:00
}
}
use cfg_if::*;
use futures_util::{AsyncRead, AsyncWrite};
use parking_lot::*;
use stop_token::*;
use thiserror::Error as ThisError;
2023-06-21 13:40:12 -04:00
pub use fn_name;
2022-11-27 22:33:41 -05:00
// For iOS tests
#[no_mangle]
2023-06-07 21:55:23 -04:00
pub extern "C" fn main_rs() {}