pub struct CrateRef {
pub name: CrateName,
pub version: Option<VersionArg>,
}Expand description
Crate reference with optional name@version sugar (R2).
Accepts plain names (serde) or @-qualified versions (clap@4.5.0,
std@stable). The @ form is agent-friendly sugar equivalent to
--crate-version.
Fields§
§name: CrateNameValidated crate name.
version: Option<VersionArg>Version from @… when present.
Implementations§
Source§impl CrateRef
impl CrateRef
Sourcepub fn parse(raw: &str) -> AppResult<Self>
pub fn parse(raw: &str) -> AppResult<Self>
Parse crate or crate@version.
§Errors
Returns ErrorKind::InvalidInput for empty parts, illegal names, or
invalid version tokens (including a forbidden v SemVer prefix).
§Examples
use docsrs_cli::domain::CrateRef;
let plain = CrateRef::parse("tokio").expect("ok");
assert_eq!(plain.name.as_str(), "tokio");
assert!(plain.version.is_none());
let at = CrateRef::parse("clap@4.5.0").expect("ok");
assert_eq!(at.name.as_str(), "clap");
assert_eq!(at.version.as_ref().unwrap().as_str(), "4.5.0");Sourcepub fn into_name_and_version(
self,
crate_version_flag: Option<&str>,
) -> AppResult<(CrateName, VersionArg)>
pub fn into_name_and_version( self, crate_version_flag: Option<&str>, ) -> AppResult<(CrateName, VersionArg)>
Merge @version sugar with an optional --crate-version flag.
Precedence: when both are present they must agree; otherwise the
non-empty source wins. Missing both → latest.
§Errors
Returns ErrorKind::InvalidInput on conflicting versions or invalid flag.
Trait Implementations§
impl Eq for CrateRef
impl StructuralPartialEq for CrateRef
Auto Trait Implementations§
impl Freeze for CrateRef
impl RefUnwindSafe for CrateRef
impl Send for CrateRef
impl Sync for CrateRef
impl Unpin for CrateRef
impl UnsafeUnpin for CrateRef
impl UnwindSafe for CrateRef
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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