haproxy_config/
line.rs

1use crate::config::{Address, Password};
2
3/// Zero copy representations of the lines in a config section. 
4pub mod borrowed;
5/// Owned representations of the lines in a config section, far easier to work with. Can be created
6/// from a [`borrowed::Line`] using [`From`]
7pub mod owned;
8
9impl<'a> From<&'a borrowed::Line<'a>> for owned::Line {
10    fn from(line: &'a borrowed::Line<'a>) -> owned::Line {
11        match line {
12            borrowed::Line::Server {
13                name,
14                addr,
15                option,
16                comment,
17            } => owned::Line::Server {
18                name: (*name).to_string(),
19                addr: Address::from(addr),
20                option: option.map(ToOwned::to_owned),
21                comment: comment.map(ToOwned::to_owned),
22            },
23            borrowed::Line::Option {
24                keyword,
25                value,
26                comment,
27            } => owned::Line::Option {
28                keyword: (*keyword).to_string(),
29                value: value.map(ToOwned::to_owned),
30                comment: comment.map(ToOwned::to_owned),
31            },
32            borrowed::Line::Bind {
33                addr,
34                value,
35                comment,
36            } => owned::Line::Bind {
37                addr: Address::from(addr),
38                value: value.map(ToOwned::to_owned),
39                comment: comment.map(ToOwned::to_owned),
40            },
41            borrowed::Line::Acl {
42                name,
43                rule,
44                comment,
45            } => owned::Line::Acl {
46                name: (*name).to_string(),
47                rule: rule.map(ToOwned::to_owned),
48                comment: comment.map(ToOwned::to_owned),
49            },
50            borrowed::Line::Backend {
51                name,
52                modifier,
53                condition,
54                comment,
55            } => owned::Line::Backend {
56                name: (*name).to_string(),
57                modifier: modifier.clone(),
58                condition: condition.map(ToOwned::to_owned),
59                comment: comment.map(ToOwned::to_owned),
60            },
61            borrowed::Line::Group {
62                name,
63                users,
64                comment,
65            } => owned::Line::Group {
66                name: (*name).to_string(),
67                users: users.iter().map(|s| (*s).to_string()).collect(),
68                comment: comment.map(ToOwned::to_owned),
69            },
70            borrowed::Line::User {
71                name,
72                password,
73                groups,
74                comment,
75            } => owned::Line::User {
76                name: (*name).to_string(),
77                password: Password::from(password),
78                groups: groups.iter().map(|s| (*s).to_string()).collect(),
79                comment: comment.map(ToOwned::to_owned),
80            },
81            borrowed::Line::SysUser { name } => owned::Line::SysUser {
82                name: (*name).to_string(),
83            },
84            borrowed::Line::Config {
85                key,
86                value,
87                comment,
88            } => owned::Line::Config {
89                key: (*key).to_string(),
90                value: value.map(ToOwned::to_owned),
91                comment: comment.map(ToOwned::to_owned),
92            },
93            borrowed::Line::Comment(s) => owned::Line::Comment((*s).to_string()),
94            borrowed::Line::Blank => owned::Line::Blank,
95        }
96    }
97}