macro_rules! impl_version {
($type:ty {
version: $version:ident,
status: $status:expr $(,)?
}) => { ... };
($type:ty {
version: $version:ident,
status: $status:expr,
published_at: $published_at:ident $(,)?
}) => { ... };
($type:ty {
version: $version:ident,
status: $status:expr,
prerelease: $prerelease:expr $(,)?
}) => { ... };
($type:ty {
version: $version:ident,
status: $status:expr,
published_at: $published_at:ident,
prerelease: $prerelease:expr $(,)?
}) => { ... };
($type:ty {
version: $version:ident,
status: $status:expr,
published_at: $published_at:ident,
prerelease: $prerelease:expr,
deprecation: $deprecation:expr $(,)?
}) => { ... };
}Expand description
Implement Version trait for a struct.
§Arguments
$type- The struct type nameversion- Field name for version string (ConcreteVersion)status- Expression evaluating to a closureFn(&$type) -> RemovalStatus, restating at every declaration site whether the ecosystem’s flag is a hard removal (RemovalStatus::from_yanked) or an advisory one (RemovalStatus::from_advisory) — seeRemovalStatus.published_at- Optional: field name for publish timestamp (Option<PublishTime>), already parsed eagerly at constructionprerelease- Optional: expression evaluating to a closureFn(&$type) -> bool, used when the ecosystem has its own reliable prerelease signal (e.g. a semver-parsedprecomponent) instead of falling back to the trait’s default hyphen-substring heuristic. Omitting this arm silently installs the default heuristic, with no compile-time signal that it may be wrong for the ecosystem — only omit it when the default is provably correct for the registry’s version format (as of #322,deps-composeris the sole deliberate holdout, since Packagist versions aren’t strict semver).deprecation- Optional, requires bothpublished_atandprereleaseto also be given: expression evaluating to a closureFn(&$type) -> Option<&Deprecation>, for an ecosystem whose registry exposes a package-level deprecation payload (issue #205). Omitting this arm installs the trait default (None).
§Examples
ⓘ
use deps_core::{ConcreteVersion, impl_version, RemovalStatus};
pub struct MyVersion {
pub version: ConcreteVersion,
pub deprecated: bool,
}
impl_version!(MyVersion {
version: version,
status: |v: &MyVersion| RemovalStatus::from_advisory(v.deprecated),
});With a publish timestamp:
ⓘ
use deps_core::{ConcreteVersion, impl_version, PublishTime, RemovalStatus};
pub struct MyVersion {
pub version: ConcreteVersion,
pub deprecated: bool,
pub published_at: Option<PublishTime>,
}
impl_version!(MyVersion {
version: version,
status: |v: &MyVersion| RemovalStatus::from_advisory(v.deprecated),
published_at: published_at,
});With a structured prerelease signal:
ⓘ
use deps_core::{ConcreteVersion, impl_version, RemovalStatus};
pub struct MyVersion {
pub version: ConcreteVersion,
pub deprecated: bool,
}
impl_version!(MyVersion {
version: version,
status: |v: &MyVersion| RemovalStatus::from_advisory(v.deprecated),
prerelease: |v: &MyVersion| v.version.as_str().contains("-pre"),
});