Parse a single group entry.
(s: impl AsRef<str>)
| 17 | impl GroupEntry { |
| 18 | /// Parse a single group entry. |
| 19 | pub fn parse_line(s: impl AsRef<str>) -> Option<Self> { |
| 20 | let mut parts = s.as_ref().splitn(4, ':'); |
| 21 | let entry = Self { |
| 22 | name: parts.next()?.to_string(), |
| 23 | passwd: parts.next()?.to_string(), |
| 24 | gid: parts.next().and_then(|s| s.parse().ok())?, |
| 25 | users: { |
| 26 | let users = parts.next()?; |
| 27 | users.split(',').map(String::from).collect() |
| 28 | }, |
| 29 | }; |
| 30 | Some(entry) |
| 31 | } |
| 32 | |
| 33 | /// Serialize entry to writer, as a group line. |
| 34 | pub fn to_writer(&self, writer: &mut impl Write) -> Result<()> { |