pub struct Resource(/* private fields */);Expand description
A normalised forge-qualified resource: github.com/acme or
github.com/acme/widgets.
Construction always goes through the vgi_core grammar, so a
Resource in hand is lowercased, names its forge, and has no empty or
dot segments. It serialises as its string form and deserialisation
re-validates, so a bridge job cannot smuggle an unnormalised one in.
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn parse(raw: &str) -> Result<Self>
pub fn parse(raw: &str) -> Result<Self>
Parse and normalise any forge-qualified resource (any depth the
grammar allows). Use Resource::parse_owner_repo when the forge is
GitHub or Forgejo.
Sourcepub fn parse_owner_repo(raw: &str) -> Result<Self>
pub fn parse_owner_repo(raw: &str) -> Result<Self>
Parse a resource on an owner[/repo] forge (GitHub, Forgejo).
On top of the shared grammar this refuses a .git suffix on the repo
segment: neither forge lets a repository be named that way, so it can
only be a clone URL pasted in the wrong place.
Sourcepub fn require_owner_repo(&self) -> Result<()>
pub fn require_owner_repo(&self) -> Result<()>
Check that this is exactly host/owner/repo under the owner/repo
grammar. A Resource that arrived by deserialisation was validated
against the general grammar only (any depth), so an adapter for an
owner/repo forge must call this before splitting it into owner and
name — github.com/acme/evil/widgets is not acme/widgets.
Sourcepub fn namespace_of(host: &str, owner: &str) -> Result<Self>
pub fn namespace_of(host: &str, owner: &str) -> Result<Self>
Build host/owner from parts, validating the result.
Sourcepub fn path_segments(&self) -> impl Iterator<Item = &str>
pub fn path_segments(&self) -> impl Iterator<Item = &str>
Path segments after the host.
Sourcepub fn repo_name(&self) -> Option<&str>
pub fn repo_name(&self) -> Option<&str>
The last path segment when the resource names a repository (more
than one path segment); None for a namespace.
Sourcepub fn is_namespace(&self) -> bool
pub fn is_namespace(&self) -> bool
Whether this is a namespace (host/owner) rather than a repository.
Sourcepub fn namespace(&self) -> Resource
pub fn namespace(&self) -> Resource
The namespace this resource sits in (host/owner); itself when it is
one.