#![doc = include_str!("../README.md")]
#![warn(
deprecated_in_future,
ffi_unwind_calls,
future_incompatible,
invalid_reference_casting,
let_underscore,
macro_use_extern_crate,
meta_variable_misuse,
missing_abi,
missing_copy_implementations,
missing_docs,
non_ascii_idents,
nonstandard_style,
noop_method_call,
rust_2018_compatibility,
rust_2018_idioms,
rust_2021_compatibility,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused,
unused_import_braces,
unused_lifetimes,
unused_qualifications,
unused_tuple_struct_fields,
variant_size_differences,
clippy::all,
clippy::cargo,
clippy::complexity,
clippy::correctness,
clippy::nursery,
clippy::pedantic,
clippy::perf,
clippy::style,
clippy::suspicious,
clippy::alloc_instead_of_core,
clippy::arithmetic_side_effects,
clippy::missing_docs_in_private_items,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks,
clippy::unnecessary_safety_comment,
clippy::unnecessary_safety_doc,
clippy::unneeded_field_pattern,
)]
#![allow(
clippy::match_bool,
clippy::module_name_repetitions,
clippy::must_use_candidate,
clippy::needless_pass_by_ref_mut,
clippy::redundant_pub_crate,
clippy::significant_drop_in_scrutinee
)]
#![cfg_attr(feature = "link", allow(dead_code, unused_imports))]
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod alloc;
#[cfg(feature = "core")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "core")))]
pub mod core;
#[cfg(feature = "cstring")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "cstring")))]
pub mod cstring;
#[cfg(feature = "env")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "env")))]
pub mod env;
#[cfg(feature = "fs")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))]
pub mod fs;
#[cfg(feature = "heap_ptr")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heap_ptr")))]
pub mod heap_ptr;
#[cfg(feature = "io")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "io")))]
pub mod io;
#[cfg(feature = "math")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "math")))]
pub mod math;
#[cfg(feature = "mutex")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "mutex")))]
pub mod mutex;
#[cfg(feature = "os")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "os")))]
pub mod os;
#[cfg(feature = "proc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "proc")))]
pub mod proc;
#[cfg(feature = "shared_lib")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "shared_lib")))]
pub mod shared_lib;
#[cfg(feature = "shared_ptr")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "shared_ptr")))]
pub mod shared_ptr;
#[cfg(feature = "string")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "string")))]
pub mod string;
#[cfg(test)]
pub(crate) mod test;
#[cfg(feature = "thread")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "thread")))]
pub mod thread;
#[cfg(feature = "time")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "time")))]
pub mod time;
#[cfg(feature = "timed_mutex")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "timed_mutex")))]
pub mod timed_mutex;
#[cfg(feature = "vec")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "vec")))]
pub mod vec;
use ::core::{
ffi::{c_char, c_void},
marker::PhantomData,
ops::{Deref, DerefMut},
ptr::{addr_of, addr_of_mut},
};
#[allow(dead_code)]
const NSTD_INT_MAX: NSTDUInt = NSTDInt::MAX as _;
pub const NSTD_NULL: NSTDAnyMut = ::core::ptr::null_mut();
pub const NSTD_FALSE: NSTDBool = false;
pub const NSTD_TRUE: NSTDBool = true;
pub type NSTDInt = isize;
pub type NSTDUInt = usize;
pub type NSTDInt8 = i8;
pub type NSTDUInt8 = u8;
pub type NSTDInt16 = i16;
pub type NSTDUInt16 = u16;
pub type NSTDInt32 = i32;
pub type NSTDUInt32 = u32;
pub type NSTDInt64 = i64;
pub type NSTDUInt64 = u64;
pub type NSTDFloat32 = f32;
pub type NSTDFloat64 = f64;
pub type NSTDChar = c_char;
pub type NSTDChar8 = NSTDUInt8;
pub type NSTDChar16 = NSTDUInt16;
pub type NSTDChar32 = NSTDUInt32;
pub type NSTDBool = bool;
pub type NSTDAny = *const c_void;
pub type NSTDAnyMut = *mut c_void;
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct NSTDRef<'a, T>(&'a c_void, PhantomData<&'a T>);
impl<T> Deref for NSTDRef<'_, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
let ptr: *const c_void = self.0;
unsafe { &*(ptr.cast()) }
}
}
impl<'a, T> From<&'a T> for NSTDRef<'a, T> {
#[inline]
fn from(value: &'a T) -> Self {
Self(unsafe { &*(addr_of!(*value).cast()) }, PhantomData)
}
}
impl<'a, T> From<&'a mut T> for NSTDRef<'a, T> {
#[inline]
fn from(value: &'a mut T) -> Self {
Self(unsafe { &*(addr_of!(*value).cast()) }, PhantomData)
}
}
#[repr(transparent)]
pub struct NSTDRefMut<'a, T>(&'a mut c_void, PhantomData<&'a mut T>);
impl<T> Deref for NSTDRefMut<'_, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
let ptr: *const c_void = self.0;
unsafe { &*(ptr.cast()) }
}
}
impl<T> DerefMut for NSTDRefMut<'_, T> {
#[inline]
fn deref_mut(&mut self) -> &mut T {
let ptr: *mut c_void = self.0;
unsafe { &mut *(ptr.cast()) }
}
}
impl<'a, T> From<&'a mut T> for NSTDRefMut<'a, T> {
#[inline]
fn from(value: &'a mut T) -> Self {
Self(unsafe { &mut *addr_of_mut!(*value).cast() }, PhantomData)
}
}
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct NSTDAnyRef<'a>(&'a c_void);
impl NSTDAnyRef<'_> {
#[inline]
const fn as_ptr<T>(&self) -> *const T {
let ptr: *const c_void = self.0;
ptr.cast()
}
#[inline]
pub const unsafe fn get<T>(&self) -> &T {
&*self.as_ptr()
}
}
impl<'a, T> From<&'a T> for NSTDAnyRef<'a> {
#[inline]
fn from(value: &'a T) -> Self {
Self(unsafe { &*(addr_of!(*value).cast()) })
}
}
impl<'a, T> From<&'a mut T> for NSTDAnyRef<'a> {
#[inline]
fn from(value: &'a mut T) -> Self {
Self(unsafe { &*(addr_of!(*value).cast()) })
}
}
#[repr(transparent)]
pub struct NSTDAnyRefMut<'a>(&'a mut c_void);
impl NSTDAnyRefMut<'_> {
#[inline]
const fn as_ptr<T>(&self) -> *const T {
let ptr: *const c_void = self.0;
ptr.cast()
}
#[inline]
fn as_mut_ptr<T>(&mut self) -> *mut T {
let ptr: *mut c_void = self.0;
ptr.cast()
}
#[inline]
pub const unsafe fn get<T>(&self) -> &T {
&*self.as_ptr()
}
#[inline]
pub unsafe fn get_mut<T>(&mut self) -> &mut T {
&mut *self.as_mut_ptr()
}
}
impl<'a, T> From<&'a mut T> for NSTDAnyRefMut<'a> {
#[inline]
fn from(value: &'a mut T) -> Self {
Self(unsafe { &mut *addr_of_mut!(*value).cast() })
}
}