pub struct Relation(/* private fields */);
Expand description
A node in the syntax tree representing a $ast
Implementations§
Source§impl Relation
impl Relation
Sourcepub fn new(
name: &str,
version_constraint: Option<(VersionConstraint, Version)>,
) -> Self
pub fn new( name: &str, version_constraint: Option<(VersionConstraint, Version)>, ) -> Self
Create a new relation
§Arguments
name
- The name of the packageversion_constraint
- The version constraint and version to use
§Example
use r_description::lossless::{Relation};
use r_description::VersionConstraint;
let relation = Relation::new("vign", Some((VersionConstraint::GreaterThanEqual, "2.0".parse().unwrap())));
assert_eq!(relation.to_string(), "vign (>= 2.0)");
Sourcepub fn wrap_and_sort(&self) -> Self
pub fn wrap_and_sort(&self) -> Self
Wrap and sort this relation
§Example
use r_description::lossless::Relation;
let relation = " vign ( >= 2.0) ".parse::<Relation>().unwrap();
assert_eq!(relation.wrap_and_sort().to_string(), "vign (>= 2.0)");
Sourcepub fn simple(name: &str) -> Self
pub fn simple(name: &str) -> Self
Create a new simple relation, without any version constraints.
§Example
use r_description::lossless::Relation;
let relation = Relation::simple("vign");
assert_eq!(relation.to_string(), "vign");
Sourcepub fn drop_constraint(&mut self) -> bool
pub fn drop_constraint(&mut self) -> bool
Remove the version constraint from the relation.
§Example
use r_description::lossless::{Relation};
use r_description::VersionConstraint;
let mut relation = Relation::new("vign", Some((VersionConstraint::GreaterThanEqual, "2.0".parse().unwrap())));
relation.drop_constraint();
assert_eq!(relation.to_string(), "vign");
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Return the name of the package in the relation.
§Example
use r_description::lossless::Relation;
let relation = Relation::simple("vign");
assert_eq!(relation.name(), "vign");
Sourcepub fn version(&self) -> Option<(VersionConstraint, Version)>
pub fn version(&self) -> Option<(VersionConstraint, Version)>
Return the version constraint and the version it is constrained to.
Sourcepub fn set_version(
&mut self,
version_constraint: Option<(VersionConstraint, Version)>,
)
pub fn set_version( &mut self, version_constraint: Option<(VersionConstraint, Version)>, )
Set the version constraint for this relation
§Example
use r_description::lossless::{Relation};
use r_description::VersionConstraint;
let mut relation = Relation::simple("vign");
relation.set_version(Some((VersionConstraint::GreaterThanEqual, "2.0".parse().unwrap())));
assert_eq!(relation.to_string(), "vign (>= 2.0)");
Sourcepub fn remove(&mut self)
pub fn remove(&mut self)
Remove this relation
§Example
use r_description::lossless::{Relation, Relations};
let mut relations: Relations = r"cli (>= 0.19.0), blah (<< 1.26.0)".parse().unwrap();
let mut relation = relations.get_relation(0).unwrap();
assert_eq!(relation.to_string(), "cli (>= 0.19.0)");
relation.remove();
assert_eq!(relations.to_string(), "blah (<< 1.26.0)");
Sourcepub fn satisfied_by(&self, package_version: impl VersionLookup + Copy) -> bool
pub fn satisfied_by(&self, package_version: impl VersionLookup + Copy) -> bool
Check if this relation is satisfied by the given package version.
Trait Implementations§
Source§impl Ord for Relation
impl Ord for Relation
Source§impl PartialOrd for Relation
impl PartialOrd for Relation
impl Eq for Relation
Auto Trait Implementations§
impl Freeze for Relation
impl !RefUnwindSafe for Relation
impl !Send for Relation
impl !Sync for Relation
impl Unpin for Relation
impl !UnwindSafe for Relation
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