pub struct Ident<'src>(/* private fields */);Expand description
A bare identifier — the kind that names a function, class, parameter,
enum case, etc. Distinct from Name, which represents possibly-qualified
names.
Memory layout is identical to &'src str (16 bytes); Option<Ident> is
also 16 bytes via the standard pointer niche. The “error” state — produced
during error recovery when no identifier was found in the source — is
represented by an empty string slice, which cannot occur for a real PHP
identifier (the lexer rejects empty matches).
Use Ident::name / Ident::ERROR to construct, Ident::as_str to
extract a real name, Ident::is_error to test for the error state.
Serialises as a JSON string for real names and null for the error state.
Implementations§
Source§impl<'src> Ident<'src>
impl<'src> Ident<'src>
Sourcepub const ERROR: Self
pub const ERROR: Self
Sentinel for “no identifier was parsed” — same memory layout as a real
Ident, distinguished by the empty-string interior.
Sourcepub fn name(s: &'src str) -> Self
pub fn name(s: &'src str) -> Self
Construct an identifier from a non-empty source slice.
Empty input is rejected in debug builds — use Ident::ERROR instead.
Sourcepub fn as_str(&self) -> Option<&'src str>
pub fn as_str(&self) -> Option<&'src str>
Returns Some(s) for a real identifier, None for the error state.