|
4 | 4 |
|
5 | 5 | use std::fmt; |
6 | 6 |
|
7 | | -use anyhow::{bail, Context, Result}; |
| 7 | +use anyhow::{Context, Result, bail}; |
8 | 8 | use serde::{Deserialize, Serialize}; |
9 | 9 |
|
10 | 10 | /// Map types corresponding to Hesiod naming conventions. |
@@ -75,7 +75,10 @@ impl PasswdRecord { |
75 | 75 | pub fn from_txt(txt: &str) -> Result<Self> { |
76 | 76 | let parts: Vec<&str> = txt.splitn(7, ':').collect(); |
77 | 77 | if parts.len() != 7 { |
78 | | - bail!("passwd record requires 7 colon-separated fields, got {}", parts.len()); |
| 78 | + bail!( |
| 79 | + "passwd record requires 7 colon-separated fields, got {}", |
| 80 | + parts.len() |
| 81 | + ); |
79 | 82 | } |
80 | 83 | Ok(Self { |
81 | 84 | username: parts[0].to_string(), |
@@ -115,7 +118,10 @@ impl GroupRecord { |
115 | 118 | pub fn from_txt(txt: &str) -> Result<Self> { |
116 | 119 | let parts: Vec<&str> = txt.splitn(4, ':').collect(); |
117 | 120 | if parts.len() != 4 { |
118 | | - bail!("group record requires 4 colon-separated fields, got {}", parts.len()); |
| 121 | + bail!( |
| 122 | + "group record requires 4 colon-separated fields, got {}", |
| 123 | + parts.len() |
| 124 | + ); |
119 | 125 | } |
120 | 126 | let members = if parts[3].is_empty() { |
121 | 127 | Vec::new() |
@@ -157,7 +163,10 @@ impl ServiceRecord { |
157 | 163 | pub fn from_txt(txt: &str) -> Result<Self> { |
158 | 164 | let parts: Vec<&str> = txt.splitn(3, ':').collect(); |
159 | 165 | if parts.len() != 3 { |
160 | | - bail!("service record requires 3 colon-separated fields, got {}", parts.len()); |
| 166 | + bail!( |
| 167 | + "service record requires 3 colon-separated fields, got {}", |
| 168 | + parts.len() |
| 169 | + ); |
161 | 170 | } |
162 | 171 | Ok(Self { |
163 | 172 | host: parts[0].to_string(), |
@@ -188,13 +197,19 @@ pub struct FilsysRecord { |
188 | 197 |
|
189 | 198 | impl FilsysRecord { |
190 | 199 | pub fn to_txt(&self) -> String { |
191 | | - format!("{} {} {} {}", self.fs_type, self.mount_path, self.source, self.mode) |
| 200 | + format!( |
| 201 | + "{} {} {} {}", |
| 202 | + self.fs_type, self.mount_path, self.source, self.mode |
| 203 | + ) |
192 | 204 | } |
193 | 205 |
|
194 | 206 | pub fn from_txt(txt: &str) -> Result<Self> { |
195 | 207 | let parts: Vec<&str> = txt.splitn(4, ' ').collect(); |
196 | 208 | if parts.len() != 4 { |
197 | | - bail!("filsys record requires 4 space-separated fields, got {}", parts.len()); |
| 209 | + bail!( |
| 210 | + "filsys record requires 4 space-separated fields, got {}", |
| 211 | + parts.len() |
| 212 | + ); |
198 | 213 | } |
199 | 214 | Ok(Self { |
200 | 215 | fs_type: parts[0].to_string(), |
@@ -289,7 +304,10 @@ mod tests { |
289 | 304 | shell: "/bin/bash".into(), |
290 | 305 | }; |
291 | 306 | let txt = record.to_txt(); |
292 | | - assert_eq!(txt, "admin:*:1000:1000:FlatRacoon Admin:/home/admin:/bin/bash"); |
| 307 | + assert_eq!( |
| 308 | + txt, |
| 309 | + "admin:*:1000:1000:FlatRacoon Admin:/home/admin:/bin/bash" |
| 310 | + ); |
293 | 311 | let parsed = PasswdRecord::from_txt(&txt).unwrap(); |
294 | 312 | assert_eq!(record, parsed); |
295 | 313 | } |
|
0 commit comments