jsbind/
null.rs

1use crate::utils::*;
2
3/// Only a single instance has semantic meaning—see [`Null::VALUE`].
4#[derive(Clone, Debug)]
5#[repr(transparent)]
6pub struct Null {
7    inner: emlite::Val,
8}
9
10impl Null {
11    /// Canonical singleton for the JS `null` value.
12    ///
13    /// Storing one constant avoids repeated calls to
14    /// `emlite::Val::null()` and communicates intent at the type level.
15    pub const VALUE: Null = Null {
16        inner: emlite::Val::null(),
17    };
18
19    /// Always returns `true` – this wrapper is, by definition, `null`.
20    #[inline]
21    pub fn is_null(&self) -> bool {
22        true
23    }
24}
25
26bind!(Null);
27
28impl crate::prelude::DynCast for Null {
29    #[inline]
30    fn instanceof(_val: &emlite::Val) -> bool {
31        false
32    }
33    #[inline]
34    fn unchecked_from_val(v: emlite::Val) -> Self {
35        v.as_::<Self>() // zero-cost new-type cast
36    }
37    #[inline]
38    fn unchecked_from_val_ref(v: &emlite::Val) -> &Self {
39        unsafe { &*(v as *const emlite::Val as *const Self) }
40    }
41}