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
//! Utilities like useful data structures and locks

#![allow(unused)]

use core::cell::UnsafeCell;
use core::fmt;
use core::mem::{align_of, size_of, size_of_val};
use core::ops::{Deref, DerefMut};

mod spin;
pub use spin::{Spin, SpinGuard};
mod ticket;
pub use ticket::{Ticket, TicketGuard};
mod once;
pub use once::{AlreadyInitialized, Once};


/// String inlined into a struct
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct InlineStr<const N: usize>(pub [u8; N]);
impl<const N: usize> InlineStr<N> {
    pub fn as_str(&self) -> &str {
        core::str::from_utf8(&self.0).unwrap_or_default()
    }
}
impl<const N: usize> fmt::Debug for InlineStr<N> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self.as_str())
    }
}

/// Zero-terminated string reference
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct RefStr(pub *const i8);
impl RefStr {
    pub fn as_str(&self) -> &str {
        if !self.0.is_null() {
            unsafe {
                core::ffi::CStr::from_ptr(self.0)
                    .to_str()
                    .unwrap_or_default()
            }
        } else {
            ""
        }
    }
}
impl fmt::Debug for RefStr {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self.as_str())
    }
}