haproxy_config/
section.rs1use std::net::Ipv4Addr;
2
3pub mod borrowed;
7pub mod owned;
10
11use crate::line::owned::Line;
12
13use crate::config::Address;
14
15impl<'a> From<&'a borrowed::Section<'a>> for owned::Section {
16 fn from(section: &'a borrowed::Section<'a>) -> Self {
17 match section {
18 borrowed::Section::BlankLine => owned::Section::BlankLine,
19 borrowed::Section::Comment(comment) => owned::Section::Comment((*comment).to_string()),
20 borrowed::Section::Global { comment, lines } => owned::Section::Global {
21 comment: comment.map(ToOwned::to_owned),
22 lines: lines.iter().map(Line::from).collect(),
23 },
24 borrowed::Section::Default {
25 comment,
26 proxy,
27 lines,
28 } => owned::Section::Default {
29 comment: comment.map(ToOwned::to_owned),
30 proxy: proxy.map(ToOwned::to_owned),
31 lines: lines.iter().map(Line::from).collect(),
32 },
33 borrowed::Section::Frontend {
34 comment,
35 proxy,
36 lines,
37 header_addr,
38 } => owned::Section::Frontend {
39 comment: comment.map(ToOwned::to_owned),
40 proxy: (*proxy).to_string(),
41 lines: lines.iter().map(Line::from).collect(),
42 header_addr: header_addr.as_ref().map(|(address_ref, config)| {
43 (Address::from(address_ref), config.map(ToOwned::to_owned))
44 }),
45 },
46 borrowed::Section::Listen {
47 comment,
48 proxy,
49 lines,
50 header_addr,
51 } => owned::Section::Listen {
52 comment: comment.map(ToOwned::to_owned),
53 proxy: (*proxy).to_string(),
54 lines: lines.iter().map(Line::from).collect(),
55 header_addr: header_addr.as_ref().map(|(address_ref, config)| {
56 (Address::from(address_ref), config.map(ToOwned::to_owned))
57 }),
58 },
59 borrowed::Section::Backend {
60 comment,
61 proxy,
62 lines,
63 } => owned::Section::Backend {
64 comment: comment.map(ToOwned::to_owned),
65 proxy: (*proxy).to_string(),
66 lines: lines.iter().map(Line::from).collect(),
67 },
68 borrowed::Section::Userlist {
69 comment,
70 name,
71 lines,
72 } => owned::Section::Userlist {
73 comment: comment.map(ToOwned::to_owned),
74 name: (*name).to_string(),
75 lines: lines.iter().map(Line::from).collect(),
76 },
77 borrowed::Section::UnknownLine { line } => owned::Section::UnknownLine {
78 line: (*line).to_string(),
79 },
80 }
81 }
82}
83
84#[derive(Debug, Clone, Hash, PartialEq, Eq)]
86pub enum HostRef<'input> {
87 Ipv4(Ipv4Addr),
88 Dns(&'input str),
89 Wildcard,
90}
91
92#[derive(Debug, Clone, Hash, PartialEq, Eq)]
94pub struct AddressRef<'input> {
95 pub host: HostRef<'input>,
96 pub port: Option<u16>,
97}
98
99#[derive(Debug, Clone, Hash, PartialEq, Eq)]
101pub enum BackendModifier {
102 If,
103 Unless,
104}
105
106#[derive(Debug)]
108pub enum PasswordRef<'input> {
109 Secure(&'input str),
110 Insecure(&'input str),
111}