feat(span): add Atom::r#static (#8479)

This allows

```rs
const TYPEOF_UNDEFINED: Atom<'static> = Atom::r#static("undefined");

#[derive(Clone, Copy)]
enum Value<'a> {
  /// Not `Atom<'a>`, which takes one more byte
  StringLiteral(&'a Atom<'a>),
  // ...
}

fn get_typeof<'a>(value: Value<'a>) -> Value<'a> {
  if ... {
    return Value::StringLiteral(&TYPEOF_UNDEFINED);
  }
}
```
This commit is contained in:
_Kerman 2025-01-14 16:51:31 +08:00 committed by GitHub
parent c444de8be1
commit 9d550aacaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,10 +20,16 @@ use crate::{cmp::ContentEq, hash::ContentHash, CompactStr};
pub struct Atom<'a>(&'a str);
impl Atom<'static> {
/// Get an [`Atom`] containing a static string.
#[inline]
pub const fn r#static(s: &'static str) -> Self {
Atom(s)
}
/// Get an [`Atom`] containing the empty string (`""`).
#[inline]
pub const fn empty() -> Self {
Atom("")
Self::r#static("")
}
}