pub struct GoPackageName(/* private fields */);Expand description
Validated Go package name metadata.
Implementations§
Source§impl GoPackageName
impl GoPackageName
Sourcepub fn new(value: impl AsRef<str>) -> Result<GoPackageName, GoPackageError>
pub fn new(value: impl AsRef<str>) -> Result<GoPackageName, GoPackageError>
Creates a package name from ASCII identifier-shaped text.
§Errors
Returns GoPackageError when the name is empty or not ASCII identifier-shaped.
Examples found in repository?
examples/basic_usage.rs (line 6)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let version: GoVersion = "go1.22.0".parse()?;
5 let identifier = GoIdentifier::new("ServeHTTP")?;
6 let package = GoPackageName::new("http")?;
7 let import = GoImportPath::new("net/http")?;
8 let module = GoModulePath::new("example.com/project")?;
9 let test = GoTestName::new("TestHandler")?;
10
11 assert_eq!(version.to_string(), "1.22.0");
12 assert!(identifier.is_exported());
13 assert_eq!(package.as_str(), "http");
14 assert_eq!(import.as_str(), "net/http");
15 assert_eq!(module.as_str(), "example.com/project");
16 assert_eq!(test.as_str(), "TestHandler");
17 Ok(())
18}Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the package name.
Examples found in repository?
examples/basic_usage.rs (line 13)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let version: GoVersion = "go1.22.0".parse()?;
5 let identifier = GoIdentifier::new("ServeHTTP")?;
6 let package = GoPackageName::new("http")?;
7 let import = GoImportPath::new("net/http")?;
8 let module = GoModulePath::new("example.com/project")?;
9 let test = GoTestName::new("TestHandler")?;
10
11 assert_eq!(version.to_string(), "1.22.0");
12 assert!(identifier.is_exported());
13 assert_eq!(package.as_str(), "http");
14 assert_eq!(import.as_str(), "net/http");
15 assert_eq!(module.as_str(), "example.com/project");
16 assert_eq!(test.as_str(), "TestHandler");
17 Ok(())
18}Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the name and returns the owned text.
Trait Implementations§
Source§impl AsRef<str> for GoPackageName
impl AsRef<str> for GoPackageName
Source§impl Clone for GoPackageName
impl Clone for GoPackageName
Source§fn clone(&self) -> GoPackageName
fn clone(&self) -> GoPackageName
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 GoPackageName
impl Debug for GoPackageName
Source§impl Display for GoPackageName
impl Display for GoPackageName
Source§impl FromStr for GoPackageName
impl FromStr for GoPackageName
Source§type Err = GoPackageError
type Err = GoPackageError
The associated error which can be returned from parsing.
Source§fn from_str(
value: &str,
) -> Result<GoPackageName, <GoPackageName as FromStr>::Err>
fn from_str( value: &str, ) -> Result<GoPackageName, <GoPackageName as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for GoPackageName
impl Hash for GoPackageName
Source§impl Ord for GoPackageName
impl Ord for GoPackageName
Source§fn cmp(&self, other: &GoPackageName) -> Ordering
fn cmp(&self, other: &GoPackageName) -> 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 GoPackageName
impl PartialEq for GoPackageName
Source§fn eq(&self, other: &GoPackageName) -> bool
fn eq(&self, other: &GoPackageName) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for GoPackageName
impl PartialOrd for GoPackageName
Source§impl TryFrom<&str> for GoPackageName
impl TryFrom<&str> for GoPackageName
Source§type Error = GoPackageError
type Error = GoPackageError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &str,
) -> Result<GoPackageName, <GoPackageName as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<GoPackageName, <GoPackageName as TryFrom<&str>>::Error>
Performs the conversion.
impl Eq for GoPackageName
impl StructuralPartialEq for GoPackageName
Auto Trait Implementations§
impl Freeze for GoPackageName
impl RefUnwindSafe for GoPackageName
impl Send for GoPackageName
impl Sync for GoPackageName
impl Unpin for GoPackageName
impl UnsafeUnpin for GoPackageName
impl UnwindSafe for GoPackageName
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