Struct ItemName
pub struct ItemName {
pub package: Option<PackageName>,
pub interface: Option<String>,
pub name: String,
}Expand description
The fully-qualified name of a Component Model item (function, type, or resource) as can be defined by wit. An item is optionally in a package, the package optionally has a version, and the item is optionally inside a namespace.
The syntax for an ItemName always uses the package version as a suffix, if it is given. The following tests show examples of the syntax for ItemName:
assert_eq!(
"foo".parse::<ItemName>().unwrap(),
ItemName {
package: None,
interface: None,
name: "foo".to_owned()
}
);
assert_eq!(
"foo.bar".parse::<ItemName>().unwrap(),
ItemName {
package: None,
interface: Some("foo".to_owned()),
name: "bar".to_owned()
}
);
assert_eq!(
"foo:bar/baz".parse::<ItemName>().unwrap(),
ItemName {
package: Some(PackageName {
namespace: "foo".to_owned(),
name: "bar".to_owned(),
version: None
}),
interface: None,
name: "baz".to_owned()
}
);
assert_eq!(
"foo:bar/baz@0.1.0".parse::<ItemName>().unwrap(),
ItemName {
package: Some(PackageName {
namespace: "foo".to_owned(),
name: "bar".to_owned(),
version: Some("0.1.0".parse().unwrap())
}),
interface: None,
name: "baz".to_owned()
}
);
assert_eq!(
"foo:bar/baz.bat".parse::<ItemName>().unwrap(),
ItemName {
package: Some(PackageName {
namespace: "foo".to_owned(),
name: "bar".to_owned(),
version: None
}),
interface: Some("baz".to_owned()),
name: "bat".to_owned()
}
);
assert_eq!(
"foo:bar/baz.bat@0.1.0".parse::<ItemName>().unwrap(),
ItemName {
package: Some(PackageName {
namespace: "foo".to_owned(),
name: "bar".to_owned(),
version: Some("0.1.0".parse().unwrap()),
}),
interface: Some("baz".to_owned()),
name: "bat".to_owned()
}
);
assert!("foo@0.1.0".parse::<ItemName>().is_err());
assert!("foo:bar@0.1.0".parse::<ItemName>().is_err());
assert!("foo:bar/baz@0.1.0.bat".parse::<ItemName>().is_err());
assert!("foo.bar@0.1.0".parse::<ItemName>().is_err());
assert!("foo@0.1.0.bar".parse::<ItemName>().is_err());Parse this from a string using its FromStr or
TryFrom<String> impls.
Display to render to the same string syntax.
Fields§
§package: Option<PackageName>§interface: Option<String>§name: StringImplementations§
§impl ItemName
impl ItemName
pub fn instance_name(&self) -> Option<String>
pub fn instance_name(&self) -> Option<String>
Get the name of the component instance containing this item, if any. The instance name will be formed like: “namespace.packagename/interfacename@0.1.0”
assert_eq!(
"foo".parse::<ItemName>().unwrap().instance_name(),
None,
);
assert_eq!(
"foo.bar".parse::<ItemName>().unwrap().instance_name(),
Some("foo".to_owned())
);
assert_eq!(
"foo:bar/baz.bat@0.1.0".parse::<ItemName>().unwrap().instance_name(),
Some("foo:bar/baz@0.1.0".to_owned())
);Trait Implementations§
§impl<'de> Deserialize<'de> for ItemName
impl<'de> Deserialize<'de> for ItemName
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ItemName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ItemName, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ItemName
impl ExportLookup for ItemName
Available on crate feature
wit-parser only.§impl Ord for ItemName
impl Ord for ItemName
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
§impl PartialOrd for ItemName
impl PartialOrd for ItemName
§impl Serialize for ItemName
impl Serialize for ItemName
§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
impl StructuralPartialEq for ItemName
Auto Trait Implementations§
impl Freeze for ItemName
impl RefUnwindSafe for ItemName
impl Send for ItemName
impl Sync for ItemName
impl Unpin for ItemName
impl UnsafeUnpin for ItemName
impl UnwindSafe for ItemName
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more