use core::marker::PhantomData;
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ShellId(pub [u8; 16]);
pub struct ShellBrand<'s> {
_brand: PhantomData<fn(&'s ()) -> &'s ()>,
}
impl<'s> Clone for ShellBrand<'s> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<'s> Copy for ShellBrand<'s> {}
impl core::fmt::Debug for ShellBrand<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("ShellBrand<'_>")
}
}
impl ShellBrand<'static> {
#[inline]
pub fn run<R, F>(f: F) -> R
where
F: for<'s> FnOnce(ShellBrand<'s>) -> R,
{
f(ShellBrand {
_brand: PhantomData,
})
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
#[test]
fn shell_id_is_copy_and_eq() {
let a = ShellId([0x11; 16]);
let b = a;
assert_eq!(a, b);
}
#[test]
fn shell_brand_scope_returns_closure_value() {
assert_eq!(ShellBrand::run(|_| 7i32), 7);
}
#[test]
fn shell_brand_is_zero_sized() {
assert_eq!(core::mem::size_of::<ShellBrand<'static>>(), 0);
}
}