Config

Struct Config 

Source
pub struct Config {
    pub global: Global,
    pub default: Default,
    pub frontends: HashMap<Name, Frontend>,
    pub backends: HashMap<Name, Backend>,
    pub listen: HashMap<Name, Listen>,
    pub userlists: HashMap<Name, Userlist>,
}
Expand description

A haproxy config where everything except config and options are fully typed. Can be created from a list of Sections using TryFrom. This type does not borrow its input.

Returns Err if the config contains errors or sections or grammar we don not supported. For example conditional blocks.

§Examples

Build a config from a list of just parsed sections.

use haproxy_config::parse_sections;
use haproxy_config::Config;

let file = include_str!("../tests/medium_haproxy.cfg");
let sections = parse_sections(file).unwrap();

let config = Config::try_from(&sections).unwrap();

The same as above however we filter out unknown lines that would result in an error. This only works for lines above the first section as anything unknown after a section starts is parsed as a config option.

use haproxy_config::parse_sections;
use haproxy_config::{Config, section::borrowed::Section};

let file = include_str!("../tests/unsupported/nonesens.cfg");
let sections = dbg!(parse_sections(file).unwrap());
let supported_sections: Vec<_> = sections.into_iter().filter(|s| !std::matches!(s,
Section::UnknownLine{..})).collect();

let config = Config::try_from(&supported_sections).unwrap();
 
// `nonesens.cfg` contained the line `this will be seen as config unfortunatly`
// its stats frontend. This is not recognised as an error unfortunatly:
assert_eq!(config.frontends
    .get("stats")
    .unwrap()
    .config.get("this")
    .unwrap()
    .as_ref()
    .unwrap(), "will be seen as a config value unfortunatly");

Fields§

§global: Global§default: Default§frontends: HashMap<Name, Frontend>§backends: HashMap<Name, Backend>§listen: HashMap<Name, Listen>§userlists: HashMap<Name, Userlist>

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<'a> TryFrom<&'a [Section<'a>]> for Config

Source§

type Error = Error

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

fn try_from(entries: &'a [Section<'a>]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a Vec<Section<'a>>> for Config

Source§

type Error = Error

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

fn try_from(vec: &'a Vec<Section<'a>>) -> Result<Self, Self::Error>

Performs the conversion.

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

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.