pub struct Deb822(/* private fields */);Expand description
An AST node representing a Deb822.
Implementations§
Source§impl Deb822
impl Deb822
Sourcepub fn wrap_and_sort(
&self,
sort_paragraphs: Option<&dyn Fn(&Paragraph, &Paragraph) -> Ordering>,
wrap_and_sort_paragraph: Option<&dyn Fn(&Paragraph) -> Paragraph>,
) -> Deb822
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 formatindentation- The indentation to useimmediate_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.
Sourcepub fn paragraphs(&self) -> impl Iterator<Item = Paragraph>
pub fn paragraphs(&self) -> impl Iterator<Item = Paragraph>
Returns an iterator over all paragraphs in the file.
Sourcepub fn insert_paragraph(&mut self, index: usize) -> Paragraph
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");Sourcepub fn remove_paragraph(&mut self, index: usize)
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(), "");Sourcepub fn add_paragraph(&mut self) -> Paragraph
pub fn add_paragraph(&mut self) -> Paragraph
Add a new empty paragraph to the end of the file.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
Read a deb822 file from the given path.
Sourcepub fn from_file_relaxed(
path: impl AsRef<Path>,
) -> Result<(Self, Vec<String>), Error>
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.
Sourcepub fn from_str_relaxed(s: &str) -> (Self, Vec<String>)
pub fn from_str_relaxed(s: &str) -> (Self, Vec<String>)
Parse a deb822 file from a string, allowing syntax errors.
Trait Implementations§
Source§impl FromIterator<Paragraph> for Deb822
impl FromIterator<Paragraph> for Deb822
impl Eq for Deb822
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> 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