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

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

§

type Error = Error<'a>

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>, Global>> for Config

§

type Error = Error<'a>

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§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.