pub struct PackageName(/* private fields */);Expand description
Validated package name metadata.
Implementations§
Source§impl PackageName
impl PackageName
Sourcepub fn new(input: &str) -> Result<PackageName, PackageJsonTextError>
pub fn new(input: &str) -> Result<PackageName, PackageJsonTextError>
Creates lightly validated package name metadata.
§Errors
Returns PackageJsonTextError when input is empty, contains whitespace, or has an invalid scoped shape.
Examples found in repository?
examples/basic_usage.rs (line 6)
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 is_scoped(&self) -> bool
pub fn is_scoped(&self) -> bool
Returns whether this package name is scoped.
Examples found in repository?
examples/basic_usage.rs (line 11)
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 PackageName
impl Clone for PackageName
Source§fn clone(&self) -> PackageName
fn clone(&self) -> PackageName
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 PackageName
impl Debug for PackageName
Source§impl<'de> Deserialize<'de> for PackageName
impl<'de> Deserialize<'de> for PackageName
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PackageName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PackageName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for PackageName
impl Display for PackageName
Source§impl FromStr for PackageName
impl FromStr for PackageName
Source§type Err = PackageJsonTextError
type Err = PackageJsonTextError
The associated error which can be returned from parsing.
Source§fn from_str(input: &str) -> Result<PackageName, <PackageName as FromStr>::Err>
fn from_str(input: &str) -> Result<PackageName, <PackageName as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for PackageName
impl Hash for PackageName
Source§impl Ord for PackageName
impl Ord for PackageName
Source§fn cmp(&self, other: &PackageName) -> Ordering
fn cmp(&self, other: &PackageName) -> 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 PackageName
impl PartialEq for PackageName
Source§fn eq(&self, other: &PackageName) -> bool
fn eq(&self, other: &PackageName) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for PackageName
impl PartialOrd for PackageName
Source§impl Serialize for PackageName
impl Serialize for PackageName
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl TryFrom<&str> for PackageName
impl TryFrom<&str> for PackageName
Source§type Error = PackageJsonTextError
type Error = PackageJsonTextError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &str,
) -> Result<PackageName, <PackageName as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<PackageName, <PackageName as TryFrom<&str>>::Error>
Performs the conversion.
impl Eq for PackageName
impl StructuralPartialEq for PackageName
Auto Trait Implementations§
impl Freeze for PackageName
impl RefUnwindSafe for PackageName
impl Send for PackageName
impl Sync for PackageName
impl Unpin for PackageName
impl UnsafeUnpin for PackageName
impl UnwindSafe for PackageName
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