feat: add group configuration (+)
will only check users of such group also cleaned some code: - Input doesn't need to be UTF-8 valid. - Main fuction is dead-simple, very readable. - Added some modularity. - Add some docs on behavior details.
This commit is contained in:
+19
-1
@@ -1,4 +1,7 @@
|
||||
use std::ffi::CStr;
|
||||
use std::{
|
||||
ffi::{CStr, OsStr},
|
||||
os::unix::ffi::OsStrExt as _,
|
||||
};
|
||||
|
||||
pub trait SliceExt {
|
||||
fn split_once_ch(&self, ch: u8) -> Option<(&[u8], &[u8])>;
|
||||
@@ -13,10 +16,15 @@ impl SliceExt for [u8] {
|
||||
}
|
||||
|
||||
pub trait CStrExt {
|
||||
fn to_os_str(&self) -> &OsStr;
|
||||
fn split_ch(&self, ch: u8) -> Option<(&[u8], &CStr)>;
|
||||
}
|
||||
|
||||
impl CStrExt for CStr {
|
||||
fn to_os_str(&self) -> &OsStr {
|
||||
OsStr::from_bytes(self.to_bytes())
|
||||
}
|
||||
|
||||
fn split_ch(&self, ch: u8) -> Option<(&[u8], &CStr)> {
|
||||
let self_slice = self.to_bytes_with_nul();
|
||||
|
||||
@@ -27,3 +35,13 @@ impl CStrExt for CStr {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait StrExt {
|
||||
fn as_os_str(&self) -> &OsStr;
|
||||
}
|
||||
|
||||
impl StrExt for str {
|
||||
fn as_os_str(&self) -> &OsStr {
|
||||
OsStr::from_bytes(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user