1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
//! Provides core functionality for `nstd`.
//!
//! The entire `nstd.core` module is dependency free and makes no use of Rust's [std] library,
//! making it fit for resource constrained/embedded environments.
pub mod cstr;
pub mod cty;
pub mod def;
pub mod fty;
pub mod ity;
pub mod math;
pub mod mem;
pub mod ops;
pub mod optional;
pub mod ptr;
pub mod range;
pub mod result;
pub mod slice;
pub mod str;
pub mod time;
pub mod unichar;
use self::str::NSTDStr;
use nstdapi::nstdapi;
/// Takes advantage of Rust's unwinding behavior by panicking while a thread is already unwinding
/// from a panic, resulting in program abortion.
struct Abort;
impl Drop for Abort {
/// Panics if Rust's panic strategy is set to unwind.
#[inline]
fn drop(&mut self) {
#[cfg(panic = "unwind")]
panic!();
}
}
/// Terminates the program immediately in an abnormal fashion.
///
/// This operation will never return.
///
/// # Panics
///
/// This operation will always panic.
#[inline]
#[nstdapi]
pub const fn nstd_core_abort() -> ! {
#[allow(unused_variables)]
let abort = Abort;
panic!();
}
/// Terminates the program immediately in an abnormal fashion with a UTF-8 encoded payload.
///
/// This operation will never return.
///
/// # Parameters:
///
/// - `const NSTDStr *msg` - The message to abort with.
///
/// # Panics
///
/// This function will always panic.
///
/// # Safety
///
/// `msg`'s data must be valid for reads.
#[inline]
#[nstdapi]
pub const unsafe fn nstd_core_abort_with_msg(msg: &NSTDStr) -> ! {
#[allow(unused_variables)]
let abort = Abort;
panic!("{}", msg.as_str());
}
/// Invokes the runtime's panic handler.
///
/// This operation will never return.
///
/// In contrast to `nstd_core_abort`, which will terminate the program immediately, this method of
/// abortion will begin unwinding the stack (when panic = "unwind"). This can be useful for Rust
/// programs that don't unwind through call frames from foreign languages.
///
/// # Panics
///
/// This function will always panic.
#[inline]
#[nstdapi]
pub const fn nstd_core_panic() -> ! {
panic!();
}
/// Invokes the runtime's panic handler with a UTF-8 encoded payload.
///
/// This operation will never return.
///
/// In contrast to `nstd_core_abort_with_msg`, which will terminate the program immediately, this
/// method of abortion will begin unwinding the stack (when panic = "unwind"). This can be useful
/// for Rust programs that don't unwind through call frames from foreign languages.
///
/// # Parameters:
///
/// - `const NSTDStr *msg` - The message to panic with.
///
/// # Panics
///
/// This function will always panic.
///
/// # Safety
///
/// `msg`'s data must be valid for reads.
#[inline]
#[nstdapi]
pub const unsafe fn nstd_core_panic_with_msg(msg: &NSTDStr) -> ! {
panic!("{}", msg.as_str());
}