musli/no_std.rs
1//! Implementation fills for `#[no_std]` environments.
2
3/// A somewhat portable, but also noisy abort implementation for no_std
4/// environments.
5///
6/// While this should ultimately cause the process to abort, it will first cause
7/// the process to panic and report it through the panic hook.
8#[cold]
9#[cfg(not(feature = "std"))]
10pub(crate) fn abort(s: &'static str) -> ! {
11 struct Abort;
12
13 // A panic during an unwinding drop leads to an abort.
14 impl Drop for Abort {
15 #[inline]
16 fn drop(&mut self) {
17 panic!()
18 }
19 }
20
21 let _a = Abort;
22 panic!("{s}")
23}
24
25#[cfg(feature = "std")]
26#[cold]
27pub(crate) fn abort(_: &'static str) -> ! {
28 ::std::process::abort();
29}