pub enum VersionConstraint {
Tag(String),
Branch(String),
Commit(String),
}Expand description
Represents different types of version constraints in AGPM.
VersionConstraint is a simple enum that categorizes version references into
three main types: Git tags (including semantic versions), Git branches, and
Git commit hashes. This classification helps AGPM route version resolution
to the appropriate handling logic.
§Variants
Tag: Semantic versions, version requirements, and Git tagsBranch: Git branch names and referencesCommit: Git commit hashes (full or abbreviated)
§Serialization
This enum implements Serialize and Deserialize for use in configuration
files and lockfiles, allowing version constraints to be persisted and restored.
§Examples
use agpm_cli::version::VersionConstraint;
// Create different constraint types
let version = VersionConstraint::Tag("1.0.0".to_string());
let branch = VersionConstraint::Branch("main".to_string());
let commit = VersionConstraint::Commit("abc123def".to_string());
// Access the string value
assert_eq!(version.as_str(), "1.0.0");
assert_eq!(branch.as_str(), "main");
assert_eq!(commit.as_str(), "abc123def");Variants§
Tag(String)
A semantic version tag (e.g., “v1.2.0”, “1.0.0”)
Branch(String)
A git branch reference (e.g., “main”, “develop”, “feature/new”)
Commit(String)
A specific git commit hash (full or abbreviated)
Implementations§
Source§impl VersionConstraint
impl VersionConstraint
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Get the string representation of this constraint.
This method extracts the underlying string value from any constraint variant, providing a uniform way to access the constraint specification regardless of its type classification.
§Returns
Returns &str containing the original constraint string.
§Examples
use agpm_cli::version::VersionConstraint;
let tag = VersionConstraint::Tag("^1.0.0".to_string());
assert_eq!(tag.as_str(), "^1.0.0");
let branch = VersionConstraint::Branch("feature/auth".to_string());
assert_eq!(branch.as_str(), "feature/auth");
let commit = VersionConstraint::Commit("abc123def456".to_string());
assert_eq!(commit.as_str(), "abc123def456");§Use Cases
This method is useful for:
- Displaying constraints in user interfaces
- Logging and debugging version resolution
- Passing constraint strings to external tools
- Serializing constraints to text formats
Trait Implementations§
Source§impl Clone for VersionConstraint
impl Clone for VersionConstraint
Source§fn clone(&self) -> VersionConstraint
fn clone(&self) -> VersionConstraint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VersionConstraint
impl Debug for VersionConstraint
Source§impl<'de> Deserialize<'de> for VersionConstraint
impl<'de> Deserialize<'de> for VersionConstraint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for VersionConstraint
impl PartialEq for VersionConstraint
Source§impl Serialize for VersionConstraint
impl Serialize for VersionConstraint
impl Eq for VersionConstraint
impl StructuralPartialEq for VersionConstraint
Auto Trait Implementations§
impl Freeze for VersionConstraint
impl RefUnwindSafe for VersionConstraint
impl Send for VersionConstraint
impl Sync for VersionConstraint
impl Unpin for VersionConstraint
impl UnwindSafe for VersionConstraint
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
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§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
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
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>
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