4 releases

0.1.3 Nov 17, 2024
0.1.2 Oct 2, 2024
0.1.1 Jun 6, 2024
0.1.0 May 30, 2024

#273 in Authentication

Download history 177/week @ 2024-10-02 16/week @ 2024-10-09 18/week @ 2024-10-16 4/week @ 2024-10-23 4/week @ 2024-10-30 17/week @ 2024-11-06 124/week @ 2024-11-13 28/week @ 2024-11-20 3/week @ 2024-11-27 13/week @ 2024-12-04 29/week @ 2024-12-11 38/week @ 2024-12-18 7/week @ 2024-12-25 50/week @ 2025-01-08 17/week @ 2025-01-15

74 downloads per month

MIT/Apache

13KB
107 lines

gecos

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.

Install

Simply install via cargo:

cargo add gecos

Usage

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");

Dependencies

~245–700KB
~16K SLoC