Struct rust_apt::config::Config

source ·
pub struct Config {}
Expand description

Struct for Apt Configuration

All apt configuration methods do not require this struct. You can call the bindings directly from raw::apt if you would like.

Implementations§

source§

impl Config

source

pub fn new() -> Self

Create a new config object and safely init the config system.

If you initialize the struct without new() or default() You will need to manually initialize the config system.

source

pub fn new_clear() -> Self

Clears all configuratations, re-initialize, and returns the config object.

source

pub fn reset(&self)

Resets the configurations.

If you’d like to clear everything and NOT reinit you can call self.clear_all or raw::config_clear_all directly

source

pub fn clear(&self, key: &str)

Clears all values from a key.

If the value is a list, the entire list is cleared. If you need to clear 1 value from a list see self.clear_value

source

pub fn clear_value(&self, key: &str, value: &str)

Clear a single value from a list. Used for removing one item in an apt configuruation list

source

pub fn clear_all(&self)

Clears all configuratations.

This will leave you with an empty configuration object and most things probably won’t work right.

source

pub fn dump(&self) -> String

Returns a string dump of configuration options separated by \n

source

pub fn find(&self, key: &str, default: &str) -> String

Find a key and return it’s value as a string.

default is what will be returned if nothing is found.

source

pub fn get(&self, key: &str) -> Option<String>

Exactly like find but takes no default and returns an option instead.

source

pub fn file(&self, key: &str, default: &str) -> String

Find a file and return it’s value as a string.

default is what will be returned if nothing is found.

key = "Dir::Cache::pkgcache" should return /var/cache/apt/pkgcache.bin

There is not much difference in self.dir and self.file

dir will return with a trailing / where file will not.

source

pub fn dir(&self, key: &str, default: &str) -> String

Find a directory and return it’s value as a string.

default is what will be returned if nothing is found.

key = "Dir::Etc::sourceparts" should return /etc/apt/sources.list.d/

There is not much difference in self.dir and self.file

dir will return with a trailing / where file will not.

source

pub fn bool(&self, key: &str, default: bool) -> bool

Same as find, but for boolean values.

source

pub fn int(&self, key: &str, default: i32) -> i32

Same as find, but for i32 values.

source

pub fn find_vector(&self, key: &str) -> Vec<String>

Return a vector for an Apt configuration list.

An example of a common key that contains a list raw::NeverAutoRemove.

source

pub fn get_architectures(&self) -> Vec<String>

Return a vector of supported architectures on this system. The main architecture is the first in the list.

source

pub fn contains(&self, key: &str) -> bool

Simply check if a key exists.

source

pub fn set(&self, key: &str, value: &str)

Set the given key to the specified value.

source

pub fn set_vector(&self, key: &str, values: &Vec<&str>)

Add strings from a vector into an apt configuration list.

If the configuration key is not a list, you will receive a vector with one item.

Example:

use rust_apt::config::Config;
let config = Config::new();

let apt_list = vec!["This", "is", "my", "apt", "list"];
// Using "AptList" here will not work and will panic.
config.set_vector("AptList", &apt_list);

Trait Implementations§

source§

impl Debug for Config

source§

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

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

impl Default for Config

source§

fn default() -> Self

Create a new config object and safely init the config system.

If you initialize the struct without new() or default() You will need to manually initialize the config system.

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.