Deb822

Struct Deb822 

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

An AST node representing a Deb822.

Implementations§

Source§

impl Deb822

Source

pub fn new() -> Deb822

Create a new empty deb822 file.

Source

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

Parse deb822 text, returning a Parse result

Source

pub fn wrap_and_sort( &self, sort_paragraphs: Option<&dyn Fn(&Paragraph, &Paragraph) -> Ordering>, wrap_and_sort_paragraph: Option<&dyn Fn(&Paragraph) -> Paragraph>, ) -> Deb822

Provide a formatter that can handle indentation and trailing separators

§Arguments
  • control - The control file to format
  • indentation - The indentation to use
  • immediate_empty_line - Whether the value should always start with an empty line. If true, then the result becomes something like “Field:\n value”. This parameter only applies to the values that will be formatted over more than one line.
  • max_line_length_one_liner - If set, then this is the max length of the value if it is crammed into a “one-liner” value. If the value(s) fit into one line, this parameter will overrule immediate_empty_line.
  • sort_paragraphs - If set, then this function will sort the paragraphs according to the given function.
  • sort_entries - If set, then this function will sort the entries according to the given function.
Source

pub fn paragraphs(&self) -> impl Iterator<Item = Paragraph>

Returns an iterator over all paragraphs in the file.

Source

pub fn insert_paragraph(&mut self, index: usize) -> Paragraph

Insert a new empty paragraph into the file after specified index.

§Examples
use deb822_edit::{Deb822, Paragraph};
let mut d: Deb822 = vec![
    vec![("Foo", "Bar"), ("Baz", "Qux")].into_iter().collect(),
    vec![("A", "B"), ("C", "D")].into_iter().collect(),
]
.into_iter()
.collect();
let mut p = d.insert_paragraph(0);
p.set("Foo", "Baz");
assert_eq!(d.to_string(), "Foo: Baz\n\nFoo: Bar\nBaz: Qux\n\nA: B\nC: D\n");
let mut another = d.insert_paragraph(1);
another.set("Y", "Z");
assert_eq!(d.to_string(), "Foo: Baz\n\nY: Z\n\nFoo: Bar\nBaz: Qux\n\nA: B\nC: D\n");
Source

pub fn remove_paragraph(&mut self, index: usize)

Remove the paragraph at the specified index from the file.

§Examples
use deb822_edit::Deb822;
let mut d: Deb822 = vec![
    vec![("Foo", "Bar"), ("Baz", "Qux")].into_iter().collect(),
    vec![("A", "B"), ("C", "D")].into_iter().collect(),
]
.into_iter()
.collect();
d.remove_paragraph(0);
assert_eq!(d.to_string(), "A: B\nC: D\n");
d.remove_paragraph(0);
assert_eq!(d.to_string(), "");
Source

pub fn add_paragraph(&mut self) -> Paragraph

Add a new empty paragraph to the end of the file.

Source

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

Read a deb822 file from the given path.

Source

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

Read a deb822 file from the given path, ignoring any syntax errors.

Source

pub fn from_str_relaxed(s: &str) -> (Self, Vec<String>)

Parse a deb822 file from a string, allowing syntax errors.

Source

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

Read a deb822 file from a Read object.

Source

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

Read a deb822 file from a Read object, allowing syntax errors.

Trait Implementations§

Source§

impl AstNode for Deb822

Source§

type Language = Lang

Source§

fn can_cast(kind: SyntaxKind) -> bool

Source§

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

Source§

fn syntax(&self) -> &SyntaxNode<Lang>

Source§

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

Source§

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

Source§

impl Clone for Deb822

Source§

fn clone(&self) -> Deb822

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 Deb822

Source§

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

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

impl Default for Deb822

Source§

fn default() -> Self

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

impl Display for Deb822

Source§

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

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

impl FromIterator<Paragraph> for Deb822

Source§

fn from_iter<T: IntoIterator<Item = Paragraph>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Deb822

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 Hash for Deb822

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Deb822

Source§

fn eq(&self, other: &Deb822) -> 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 Deb822

Source§

impl StructuralPartialEq for Deb822

Auto Trait Implementations§

§

impl Freeze for Deb822

§

impl !RefUnwindSafe for Deb822

§

impl !Send for Deb822

§

impl !Sync for Deb822

§

impl Unpin for Deb822

§

impl !UnwindSafe for Deb822

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.