pub struct Relations(/* private fields */);Expand description
A node in the syntax tree representing a $ast
Implementations§
Source§impl Relations
impl Relations
Sourcepub fn wrap_and_sort(self) -> Self
pub fn wrap_and_sort(self) -> Self
Wrap and sort this relations field
Sourcepub fn entries(&self) -> impl Iterator<Item = Entry> + '_
pub fn entries(&self) -> impl Iterator<Item = Entry> + '_
Iterate over the entries in this relations field
Sourcepub fn iter(&self) -> impl Iterator<Item = Entry> + '_
pub fn iter(&self) -> impl Iterator<Item = Entry> + '_
Iterate over the entries in this relations field
Sourcepub fn remove_entry(&mut self, idx: usize) -> Entry
pub fn remove_entry(&mut self, idx: usize) -> Entry
Remove the entry at the given index
Sourcepub fn insert_with_separator(
&mut self,
idx: usize,
entry: Entry,
default_sep: Option<&str>,
)
pub fn insert_with_separator( &mut self, idx: usize, entry: Entry, default_sep: Option<&str>, )
Insert a new entry at the given index
§Arguments
idx- The index to insert atentry- The entry to insertdefault_sep- Optional default separator to use if no pattern is detected (defaults to “ “)
Sourcepub fn insert(&mut self, idx: usize, entry: Entry)
pub fn insert(&mut self, idx: usize, entry: Entry)
Insert a new entry at the given index with default separator
Sourcepub fn substvars(&self) -> impl Iterator<Item = String> + '_
pub fn substvars(&self) -> impl Iterator<Item = String> + '_
Return the names of substvars in this relations field
Sourcepub fn parse_relaxed(s: &str, allow_substvar: bool) -> (Relations, Vec<String>)
pub fn parse_relaxed(s: &str, allow_substvar: bool) -> (Relations, Vec<String>)
Parse a relations field from a string, allowing syntax errors
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 relations field is satisfied by the given package versions.
Sourcepub fn ensure_minimum_version(
&mut self,
package: &str,
minimum_version: &Version,
)
pub fn ensure_minimum_version( &mut self, package: &str, minimum_version: &Version, )
Ensure that a package has at least a minimum version constraint.
If the package already exists with a version constraint that satisfies the minimum version, it is left unchanged. Otherwise, the constraint is updated or added.
§Arguments
package- The package nameminimum_version- The minimum version required
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "debhelper (>= 9)".parse().unwrap();
relations.ensure_minimum_version("debhelper", &"12".parse().unwrap());
assert_eq!(relations.to_string(), "debhelper (>= 12)");
let mut relations: Relations = "python3".parse().unwrap();
relations.ensure_minimum_version("debhelper", &"12".parse().unwrap());
assert!(relations.to_string().contains("debhelper (>= 12)"));Sourcepub fn ensure_exact_version(&mut self, package: &str, version: &Version)
pub fn ensure_exact_version(&mut self, package: &str, version: &Version)
Ensure that a package has an exact version constraint.
§Arguments
package- The package nameversion- The exact version required
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "debhelper (>= 9)".parse().unwrap();
relations.ensure_exact_version("debhelper", &"12".parse().unwrap());
assert_eq!(relations.to_string(), "debhelper (= 12)");Sourcepub fn ensure_some_version(&mut self, package: &str)
pub fn ensure_some_version(&mut self, package: &str)
Ensure that a package dependency exists, without specifying a version.
If the package already exists (with or without a version constraint), the relations field is left unchanged. Otherwise, the package is added without a version constraint.
§Arguments
package- The package name
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "python3".parse().unwrap();
relations.ensure_some_version("debhelper");
assert!(relations.to_string().contains("debhelper"));Sourcepub fn ensure_substvar(&mut self, substvar: &str) -> Result<(), String>
pub fn ensure_substvar(&mut self, substvar: &str) -> Result<(), String>
Ensure that a substitution variable is present in the relations.
If the substvar already exists, it is left unchanged. Otherwise, it is added at the end of the relations list.
§Arguments
substvar- The substitution variable (e.g., “${misc:Depends}”)
§Returns
Ok(()) on success, or Err with an error message if parsing fails
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "python3".parse().unwrap();
relations.ensure_substvar("${misc:Depends}").unwrap();
assert_eq!(relations.to_string(), "python3, ${misc:Depends}");Sourcepub fn filter_entries<F>(&mut self, keep: F)
pub fn filter_entries<F>(&mut self, keep: F)
Filter entries based on a predicate function.
§Arguments
keep- A function that returns true for entries to keep
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "python3, debhelper, rustc".parse().unwrap();
relations.filter_entries(|entry| {
entry.relations().any(|r| r.name().starts_with("python"))
});
assert_eq!(relations.to_string(), "python3");Sourcepub fn is_sorted(&self, sorting_order: &impl SortingOrder) -> bool
pub fn is_sorted(&self, sorting_order: &impl SortingOrder) -> bool
Check whether the relations are sorted according to a given sorting order.
§Arguments
sorting_order- The sorting order to check against
§Example
use debian_control::lossless::relations::{Relations, WrapAndSortOrder};
let relations: Relations = "debhelper, python3, rustc".parse().unwrap();
assert!(relations.is_sorted(&WrapAndSortOrder));
let relations: Relations = "rustc, debhelper, python3".parse().unwrap();
assert!(!relations.is_sorted(&WrapAndSortOrder));Sourcepub fn drop_dependency(&mut self, package: &str) -> bool
pub fn drop_dependency(&mut self, package: &str) -> bool
Drop a dependency from the relations by package name.
§Arguments
package- The package name to remove
§Returns
true if the package was found and removed, false otherwise
§Example
use debian_control::lossless::relations::Relations;
let mut relations: Relations = "python3, debhelper, rustc".parse().unwrap();
assert!(relations.drop_dependency("debhelper"));
assert_eq!(relations.to_string(), "python3, rustc");
assert!(!relations.drop_dependency("nonexistent"));Sourcepub fn add_dependency(&mut self, entry: Entry, position: Option<usize>)
pub fn add_dependency(&mut self, entry: Entry, position: Option<usize>)
Add a dependency at a specific position or auto-detect the position.
If position is None, the position is automatically determined based
on the detected sorting order. If a sorting order is detected, the entry
is inserted in the appropriate position to maintain that order. Otherwise,
it is appended at the end.
§Arguments
entry- The entry to addposition- Optional position to insert at
§Example
use debian_control::lossless::relations::{Relations, Relation, Entry};
let mut relations: Relations = "python3, rustc".parse().unwrap();
let entry = Entry::from(Relation::simple("debhelper"));
relations.add_dependency(entry, None);
// debhelper is inserted in sorted order (if order is detected)Sourcepub fn get_relation(&self, package: &str) -> Result<(usize, Entry), String>
pub fn get_relation(&self, package: &str) -> Result<(usize, Entry), String>
Get the entry containing a specific package.
This returns the first entry that contains exactly one relation with the specified package name (no alternatives).
§Arguments
package- The package name to search for
§Returns
A tuple of (index, Entry) if found
§Errors
Returns Err with a message if the package is found in a complex rule (with alternatives)
§Example
use debian_control::lossless::relations::Relations;
let relations: Relations = "python3, debhelper (>= 12), rustc".parse().unwrap();
let (idx, entry) = relations.get_relation("debhelper").unwrap();
assert_eq!(idx, 1);
assert_eq!(entry.to_string(), "debhelper (>= 12)");Sourcepub fn iter_relations_for(
&self,
package: &str,
) -> impl Iterator<Item = (usize, Entry)> + '_
pub fn iter_relations_for( &self, package: &str, ) -> impl Iterator<Item = (usize, Entry)> + '_
Iterate over all entries containing a specific package.
§Arguments
package- The package name to search for
§Returns
An iterator over tuples of (index, Entry)
§Example
use debian_control::lossless::relations::Relations;
let relations: Relations = "python3 | python3-minimal, python3-dev".parse().unwrap();
let entries: Vec<_> = relations.iter_relations_for("python3").collect();
assert_eq!(entries.len(), 1);Sourcepub fn has_relation(&self, package: &str) -> bool
pub fn has_relation(&self, package: &str) -> bool
Check whether a package exists in the relations.
§Arguments
package- The package name to search for
§Returns
true if the package is found, false otherwise
§Example
use debian_control::lossless::relations::Relations;
let relations: Relations = "python3, debhelper, rustc".parse().unwrap();
assert!(relations.has_relation("debhelper"));
assert!(!relations.has_relation("nonexistent"));