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