Struct TemplatedControlEditor

Source
pub struct TemplatedControlEditor { /* private fields */ }
Expand description

An editor for a control file that may be generated from a template.

This editor will automatically expand the template if it does not exist. It will also automatically update the template if the control file is changed.

§Example

use std::path::Path;
use debian_analyzer::control::TemplatedControlEditor;
let td = tempfile::tempdir().unwrap();
let mut editor = TemplatedControlEditor::create(td.path().join("control")).unwrap();
editor.add_source("foo").set_architecture(Some("all"));
editor.commit().unwrap();

Implementations§

Source§

impl TemplatedControlEditor

Source

pub fn create<P: AsRef<Path>>(control_path: P) -> Result<Self, EditorError>

Create a new control file editor.

Source

pub fn template_type(&self) -> Option<TemplateType>

Return the type of the template used to generate the control file.

Source

pub fn open<P: AsRef<Path>>(control_path: P) -> Result<Self, EditorError>

Open an existing control file.

Source

pub fn new<P: AsRef<Path>>( control_path: P, allow_missing: bool, ) -> Result<Self, EditorError>

Create a new control file editor.

Source

pub fn commit(&self) -> Result<Vec<PathBuf>, EditorError>

Commit the changes to the control file and template.

Methods from Deref<Target = Control>§

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 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 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

Trait Implementations§

Source§

impl DerefMut for TemplatedControlEditor

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Editor<Control> for TemplatedControlEditor

Source§

fn orig_content(&self) -> Option<&[u8]>

The original content, if any - without reformatting
Source§

fn updated_content(&self) -> Option<Vec<u8>>

The updated content, if any
Source§

fn rewritten_content(&self) -> Option<&[u8]>

The original content, but rewritten with our parser/serializer
Source§

fn is_generated(&self) -> bool

Check if the file is generated
Source§

fn commit(&self) -> Result<Vec<PathBuf>, EditorError>

Commit the changes Read more
Source§

fn has_changed(&self) -> bool

Whether the file has changed
Source§

impl Deref for TemplatedControlEditor

Source§

type Target = Control

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<E> AbstractControlEditor for E
where E: Editor<Control>,

Source§

fn source<'a>(&'a mut self) -> Option<Box<dyn AbstractSource<'a> + 'a>>

Get the source package.
Source§

fn binaries<'a>(&'a mut self) -> Vec<Box<dyn AbstractBinary + 'a>>

Get the binary packages.
Source§

fn commit(&self) -> bool

Commit the changes.
Source§

fn wrap_and_sort(&mut self)

Wrap and sort the control file.
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> MaybeSendSync for T