#![deny(
missing_docs,
missing_debug_implementations,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
bad_style,
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unions_with_drop_fields,
unused_allocation,
unused_comparisons,
unused_parens,
while_true
)]
#![doc(html_root_url = "https://docs.rs/voluntary_servitude/4.0.7/voluntary-servitude")]
#![cfg_attr(docs_rs_workaround, feature(doc_cfg))]
#[macro_export]
macro_rules! vs {
() => (voluntary_servitude![]);
($elem: expr; $n: expr) => (voluntary_servitude![$elem; $n]);
($($x: expr),+) => (voluntary_servitude![$($x),+]);
($($x: expr,)+) => (voluntary_servitude![$($x,)+]);
}
#[macro_export]
macro_rules! voluntary_servitude {
() => ($crate::VS::default());
($elem: expr; $n: expr) => {{
let vs = $crate::VS::default();
for _ in 0..$n {
vs.append($elem);
}
vs
}};
($($x: expr),+) => (voluntary_servitude![$($x,)+]);
($($x: expr,)+) => {{
let vs = $crate::VS::default();
$(vs.append($x);)+
vs
}};
}
#[macro_use]
#[cfg(not(feature = "logs"))]
#[allow(unused)]
mod mock {
macro_rules! trace(($($x:tt)*) => ());
macro_rules! debug(($($x:tt)*) => ());
macro_rules! info(($($x:tt)*) => ());
macro_rules! warn(($($x:tt)*) => ());
macro_rules! error(($($x:tt)*) => ());
}
pub mod atomics;
mod iterator;
mod node;
mod traits;
mod voluntary_servitude;
#[allow(unused)]
mod prelude {
pub(crate) use crate::atomics::{Atomic, AtomicOption, FillOnceAtomicOption};
pub(crate) use crate::{IntoPtr, NotEmpty};
pub(crate) use crate::{Iter, VoluntaryServitude, VS};
#[cfg(feature = "logs")]
pub use log::{debug, error, info, trace, warn};
}
use std::{error::Error, fmt, fmt::Debug, fmt::Display, fmt::Formatter};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)]
pub struct NotEmpty;
impl Debug for NotEmpty {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "NotEmpty")
}
}
impl Display for NotEmpty {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "not empty")
}
}
impl Error for NotEmpty {}
pub use crate::iterator::Iter;
pub use crate::voluntary_servitude::{VoluntaryServitude, VS};
use std::ptr::null_mut;
pub(crate) trait IntoPtr<T> {
fn into_ptr(self) -> *mut T;
}
impl<T> IntoPtr<T> for T {
#[inline]
#[must_use]
fn into_ptr(self) -> *mut Self {
Box::into_raw(Box::new(self))
}
}
impl<T> IntoPtr<T> for Option<T> {
#[inline]
#[must_use]
fn into_ptr(self) -> *mut T {
self.map(Box::new).into_ptr()
}
}
impl<T> IntoPtr<T> for Box<T> {
#[inline]
#[must_use]
fn into_ptr(self) -> *mut T {
Self::into_raw(self)
}
}
impl<T> IntoPtr<T> for Option<Box<T>> {
#[inline]
#[must_use]
fn into_ptr(self) -> *mut T {
self.map_or(null_mut(), Box::into_raw)
}
}
#[cfg(test)]
pub fn setup_logger() {
use std::sync::Once;
#[allow(unused)]
static INITIALIZE: Once = Once::new();
#[cfg(feature = "logs")]
INITIALIZE.call_once(env_logger::init);
}