pub struct JsIdentifier(/* private fields */);Expand description
Validated ASCII-safe JavaScript identifier.
Implementations§
Source§impl JsIdentifier
impl JsIdentifier
Sourcepub fn new(input: &str) -> Result<JsIdentifier, JsIdentifierError>
pub fn new(input: &str) -> Result<JsIdentifier, JsIdentifierError>
Creates an ASCII-safe JavaScript identifier.
§Errors
Returns JsIdentifierError when input is empty or not ASCII identifier-shaped.
Examples found in repository?
examples/basic_usage.rs (line 5)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let target: EcmaScriptTarget = "es2024".parse()?;
5 let identifier = JsIdentifier::new("createApp")?;
6 let package = PackageName::new("@rustuse/example")?;
7 let component = ReactComponentName::new("AppShell")?;
8
9 assert_eq!(target.to_string(), "ES2024");
10 assert_eq!(identifier.as_str(), "createApp");
11 assert!(package.is_scoped());
12 assert_eq!(component.as_str(), "AppShell");
13 Ok(())
14}Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the identifier as a string slice.
Examples found in repository?
examples/basic_usage.rs (line 10)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let target: EcmaScriptTarget = "es2024".parse()?;
5 let identifier = JsIdentifier::new("createApp")?;
6 let package = PackageName::new("@rustuse/example")?;
7 let component = ReactComponentName::new("AppShell")?;
8
9 assert_eq!(target.to_string(), "ES2024");
10 assert_eq!(identifier.as_str(), "createApp");
11 assert!(package.is_scoped());
12 assert_eq!(component.as_str(), "AppShell");
13 Ok(())
14}Trait Implementations§
Source§impl Clone for JsIdentifier
impl Clone for JsIdentifier
Source§fn clone(&self) -> JsIdentifier
fn clone(&self) -> JsIdentifier
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 JsIdentifier
impl Debug for JsIdentifier
Source§impl Display for JsIdentifier
impl Display for JsIdentifier
Source§impl FromStr for JsIdentifier
impl FromStr for JsIdentifier
Source§type Err = JsIdentifierError
type Err = JsIdentifierError
The associated error which can be returned from parsing.
Source§fn from_str(input: &str) -> Result<JsIdentifier, <JsIdentifier as FromStr>::Err>
fn from_str(input: &str) -> Result<JsIdentifier, <JsIdentifier as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for JsIdentifier
impl Hash for JsIdentifier
Source§impl Ord for JsIdentifier
impl Ord for JsIdentifier
Source§fn cmp(&self, other: &JsIdentifier) -> Ordering
fn cmp(&self, other: &JsIdentifier) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for JsIdentifier
impl PartialEq for JsIdentifier
Source§fn eq(&self, other: &JsIdentifier) -> bool
fn eq(&self, other: &JsIdentifier) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for JsIdentifier
impl PartialOrd for JsIdentifier
Source§impl TryFrom<&str> for JsIdentifier
impl TryFrom<&str> for JsIdentifier
Source§type Error = JsIdentifierError
type Error = JsIdentifierError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &str,
) -> Result<JsIdentifier, <JsIdentifier as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<JsIdentifier, <JsIdentifier as TryFrom<&str>>::Error>
Performs the conversion.
impl Eq for JsIdentifier
impl StructuralPartialEq for JsIdentifier
Auto Trait Implementations§
impl Freeze for JsIdentifier
impl RefUnwindSafe for JsIdentifier
impl Send for JsIdentifier
impl Sync for JsIdentifier
impl Unpin for JsIdentifier
impl UnsafeUnpin for JsIdentifier
impl UnwindSafe for JsIdentifier
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