Struct Control

Source
pub struct Control(/* private fields */);
Expand description

A Debian control file

Implementations§

Source§

impl Control

Source

pub fn new() -> Self

Create a new control file

Source

pub fn as_mut_deb822(&mut self) -> &mut Deb822

Return the underlying deb822 object, mutable

Source

pub fn as_deb822(&self) -> &Deb822

Return the underlying deb822 object

Source

pub fn parse(text: &str) -> Parse<Control>

Parse control file text, returning a Parse result

Source

pub fn source(&self) -> Option<Source>

Return the source package

Source

pub fn binaries(&self) -> impl Iterator<Item = Binary>

Iterate over all binary packages

Source

pub fn add_source(&mut self, name: &str) -> Source

Add a new source package

§Arguments
  • name - The name of the source package
§Returns

The newly created source package

§Example
use debian_control::lossless::control::Control;
let mut control = Control::new();
let source = control.add_source("foo");
assert_eq!(source.name(), Some("foo".to_owned()));
Source

pub fn add_binary(&mut self, name: &str) -> Binary

Add new binary package

§Arguments
  • name - The name of the binary package
§Returns

The newly created binary package

§Example
use debian_control::lossless::control::Control;
let mut control = Control::new();
let binary = control.add_binary("foo");
assert_eq!(binary.name(), Some("foo".to_owned()));
Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Read a control file from a file

Source

pub fn from_file_relaxed<P: AsRef<Path>>( path: P, ) -> Result<(Self, Vec<String>), Error>

Read a control file from a file, allowing syntax errors

Source

pub fn read<R: Read>(r: R) -> Result<Self, Error>

Read a control file from a reader

Source

pub fn read_relaxed<R: Read>(r: R) -> Result<(Self, Vec<String>), Error>

Read a control file from a reader, allowing syntax errors

Source

pub fn wrap_and_sort( &mut self, indentation: Indentation, immediate_empty_line: bool, max_line_length_one_liner: Option<usize>, )

Wrap and sort the control file

§Arguments
  • indentation - The indentation to use
  • immediate_empty_line - Whether to add an empty line at the start of multi-line fields
  • max_line_length_one_liner - The maximum line length for one-liner fields
Source

pub fn fields_in_range( &self, range: TextRange, ) -> impl Iterator<Item = Entry> + '_

Iterate over fields that overlap with the given range

This method returns all fields (entries) from all paragraphs that have any overlap with the specified text range. This is useful for incremental parsing in LSP contexts where you only want to process fields that were affected by a text change.

§Arguments
  • range - The text range to check for overlaps
§Returns

An iterator over all Entry items that overlap with the given range

§Example
use debian_control::lossless::Control;
use deb822_lossless::TextRange;

let control_text = "Source: foo\nMaintainer: test@example.com\n\nPackage: bar\nArchitecture: all\n";
let control: Control = control_text.parse().unwrap();

// Get fields in a specific range (e.g., where a change occurred)
let change_range = TextRange::new(20.into(), 40.into());
for entry in control.fields_in_range(change_range) {
    if let Some(key) = entry.key() {
        println!("Field {} was in the changed range", key);
    }
}

Trait Implementations§

Source§

impl AstNode for Control

Source§

type Language = Lang

Source§

fn can_cast(kind: <Self::Language as Language>::Kind) -> bool

Source§

fn cast(syntax: SyntaxNode<Self::Language>) -> Option<Self>

Source§

fn syntax(&self) -> &SyntaxNode<Self::Language>

Source§

fn clone_for_update(&self) -> Self
where Self: Sized,

Source§

fn clone_subtree(&self) -> Self
where Self: Sized,

Source§

impl Clone for Control

Source§

fn clone(&self) -> Control

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Control

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Control

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Control

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Control> for Deb822

Source§

fn from(c: Control) -> Self

Converts to this type from the input type.
Source§

impl From<Deb822> for Control

Source§

fn from(d: Deb822) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Control

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Control

Source§

fn eq(&self, other: &Control) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Control

Source§

impl StructuralPartialEq for Control

Auto Trait Implementations§

§

impl Freeze for Control

§

impl !RefUnwindSafe for Control

§

impl !Send for Control

§

impl !Sync for Control

§

impl Unpin for Control

§

impl !UnwindSafe for Control

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,