Crates.io | gecos |
lib.rs | gecos |
version | 0.1.2 |
source | src |
created_at | 2024-05-30 20:52:56.496155 |
updated_at | 2024-10-02 11:31:37.727286 |
description | Provides parsing and generation of gecos strings |
homepage | |
repository | https://rechenknecht.net/mixxplorer/libraries/gecos |
max_upload_size | |
id | 1257250 |
size | 14,771 |
This is a rust library to generate and parse gecos.
We started developing this library to be used in conjunction with libnss. For example, this library is used in the guest-users nss package.
Simply install via cargo
:
cargo add gecos
For a full reference, please check out the [Gecos
] struct.
use std::convert::TryFrom;
use gecos::{Gecos, GecosSanitizedString};
// read gecos string from passwd etc.
let raw_gecos_string = "Some Person,Room,Work phone,Home phone,Other 1,Other 2";
let mut gecos = Gecos::from_gecos_string(raw_gecos_string).unwrap();
// access fields like
// var field option for comp
assert_eq!(gecos.full_name.as_ref().unwrap().to_string(), "Some Person");
// and you even can convert it back to a raw gecos string
assert_eq!(gecos.to_gecos_string(), raw_gecos_string);
// modifying fields work like this
gecos.full_name = Some("Another name".to_string().try_into().unwrap());
// or more explicitly
gecos.room = Some(GecosSanitizedString::new("St. 9".to_string()).unwrap());
assert_eq!(gecos.full_name.as_ref().unwrap().to_string(), "Another name");
assert_eq!(gecos.room.as_ref().unwrap().to_string(), "St. 9");