Enum routing::resolving::ComponentAddress
source · pub enum ComponentAddress {
Absolute {
url: Url,
},
RelativePath {
scheme: String,
url: Url,
context: ComponentResolutionContext,
},
}
Expand description
Indicates the kind of ComponentAddress
, and holds ComponentAddress
properties specific to its kind. Note that there is no kind for a relative
resource component URL (a URL that only contains a resource fragment, such
as #meta/comp.cm
) because ComponentAddress::from()
will translate a
resource fragment component URL into one of the fully-resolvable
ComponentAddress
s.
Variants§
Absolute
A fully-qualified component URL.
RelativePath
A relative Component URL, starting with the package path; for example a subpackage relative URL such as “needed_package#meta/dep_component.cm”.
Fields
scheme: String
This is the scheme of the ancestor component’s absolute URL, used to identify the
Resolver
in a ResolverRegistry
.
url: Url
The relative URL, represented as a url::Url
with the relative:///
base prefix.
url::Url
cannot represent relative urls directly.
context: ComponentResolutionContext
An opaque value (from the perspective of component resolution)
required by the resolver when resolving a relative package path.
For a given child component, this property is populated from a
parent component’s resolution_context
, as returned by the parent
component’s resolver.
Implementations§
source§impl ComponentAddress
impl ComponentAddress
sourcepub fn from_absolute_url(component_url: &Url) -> Result<Self, ResolverError>
pub fn from_absolute_url(component_url: &Url) -> Result<Self, ResolverError>
Parse the given absolute component_url
and create a ComponentAddress
with kind Absolute
.
sourcepub async fn from<C: ComponentInstanceInterface>(
component_url: &Url,
component: &Arc<C>
) -> Result<Self, ResolverError>
pub async fn from<C: ComponentInstanceInterface>( component_url: &Url, component: &Arc<C> ) -> Result<Self, ResolverError>
Parse the given component_url
to determine if it is an absolute URL,
a relative subpackage URL, or a relative resource URL, and return the
corresponding ComponentAddress
enum variant and value. If the URL is
relative, use the component instance to get the required resolution
context from the component’s parent.
sourcepub fn clone_with_new_resource(
&self,
some_resource: Option<&str>
) -> Result<Self, ResolverError>
pub fn clone_with_new_resource( &self, some_resource: Option<&str> ) -> Result<Self, ResolverError>
Creates a new ComponentAddress
from self
by replacing only the
component URL resource.
sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
True if the address is Absolute
.
sourcepub fn is_relative_path(&self) -> bool
pub fn is_relative_path(&self) -> bool
True if the address is RelativePath
.
sourcepub fn context(&self) -> &ComponentResolutionContext
pub fn context(&self) -> &ComponentResolutionContext
Returns the ComponentResolutionContext
value required to resolve for a
RelativePath
component URL.
Panics if called for an Absolute
component address.
sourcepub fn scheme(&self) -> &str
pub fn scheme(&self) -> &str
Returns the URL scheme either provided for an Absolute
URL or derived
from the component’s parent. The scheme is used to look up a registered
resolver, when resolving the component.
sourcepub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Returns the optional query value for an Absolute
component URL.
Always returns None
for Relative
component URLs.
sourcepub fn resource(&self) -> Option<&str>
pub fn resource(&self) -> Option<&str>
Returns the optional component resource, from the URL fragment.
sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the resolver-ready URL string and, if it is a RelativePath
,
Some(context)
, or None
for an Absolute
address.
sourcepub fn to_url_and_context(&self) -> (&str, Option<&ComponentResolutionContext>)
pub fn to_url_and_context(&self) -> (&str, Option<&ComponentResolutionContext>)
Returns the url()
and Some(context)
for resolving the URL,
if the kind is RelativePath
(or None
if Absolute
).
Trait Implementations§
source§impl Clone for ComponentAddress
impl Clone for ComponentAddress
source§fn clone(&self) -> ComponentAddress
fn clone(&self) -> ComponentAddress
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ComponentAddress
impl Debug for ComponentAddress
source§impl PartialEq for ComponentAddress
impl PartialEq for ComponentAddress
source§fn eq(&self, other: &ComponentAddress) -> bool
fn eq(&self, other: &ComponentAddress) -> bool
self
and other
values to be equal, and is used
by ==
.