pub struct Identifier(/* private fields */);Expand description
A validated JavaScript identifier.
Identifiers are validated at construction time to ensure they:
- Are not reserved words
- Contain only valid characters
- Don’t start with a digit
Implementations§
Source§impl Identifier
impl Identifier
Sourcepub const RESERVED_WORDS: &'static [&'static str]
pub const RESERVED_WORDS: &'static [&'static str]
JavaScript reserved words that cannot be used as identifiers.
Sourcepub fn new(name: impl Into<String>) -> Result<Self>
pub fn new(name: impl Into<String>) -> Result<Self>
Create a new identifier, validating it.
§Errors
Returns an error if the identifier is:
- Empty
- A reserved word
- Contains invalid characters
- Starts with a digit
Sourcepub fn new_unchecked(name: &'static str) -> Self
pub fn new_unchecked(name: &'static str) -> Self
Create an identifier without validation (for trusted input).
§Safety
This is not unsafe in the memory sense, but it bypasses validation. Only use for identifiers known to be valid at compile time.
Trait Implementations§
Source§impl Clone for Identifier
impl Clone for Identifier
Source§fn clone(&self) -> Identifier
fn clone(&self) -> Identifier
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Identifier
impl Debug for Identifier
Source§impl<'de> Deserialize<'de> for Identifier
impl<'de> Deserialize<'de> for Identifier
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Identifier
impl Display for Identifier
Source§impl Hash for Identifier
impl Hash for Identifier
Source§impl PartialEq for Identifier
impl PartialEq for Identifier
Source§fn eq(&self, other: &Identifier) -> bool
fn eq(&self, other: &Identifier) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for Identifier
impl Serialize for Identifier
impl Eq for Identifier
impl StructuralPartialEq for Identifier
Auto Trait Implementations§
impl Freeze for Identifier
impl RefUnwindSafe for Identifier
impl Send for Identifier
impl Sync for Identifier
impl Unpin for Identifier
impl UnsafeUnpin for Identifier
impl UnwindSafe for Identifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more