1
+ use std:: collections:: HashSet ;
1
2
use std:: {
2
3
collections:: { BTreeMap , BTreeSet } ,
3
4
fs,
@@ -13,12 +14,12 @@ pub struct Entry {
13
14
name : String ,
14
15
password : String ,
15
16
gid : u32 ,
16
- user_list : Vec < String > ,
17
+ user_list : HashSet < String > ,
17
18
}
18
19
19
20
impl Entry {
20
21
/// Create a new /etc/group entry.
21
- pub fn new ( name : String , gid : u32 , user_list : Vec < String > ) -> Self {
22
+ pub fn new ( name : String , gid : u32 , user_list : HashSet < String > ) -> Self {
22
23
Self {
23
24
name,
24
25
password : "x" . into ( ) ,
@@ -28,7 +29,7 @@ impl Entry {
28
29
}
29
30
30
31
/// Update an /etc/group entry.
31
- pub fn update ( & mut self , user_list : Vec < String > ) {
32
+ pub fn update ( & mut self , user_list : HashSet < String > ) {
32
33
if self . user_list != user_list {
33
34
log:: info!(
34
35
"Updating members of group {} from {:?} to {user_list:?}..." ,
@@ -76,16 +77,16 @@ impl Entry {
76
77
}
77
78
78
79
/// Split a string containing group members separated by `,` into a list.
79
- fn split_group_members ( s : & str ) -> Vec < String > {
80
+ fn split_group_members ( s : & str ) -> HashSet < String > {
80
81
if s. is_empty ( ) {
81
- return Vec :: new ( ) ;
82
+ return HashSet :: new ( ) ;
82
83
}
83
84
s. split ( ',' ) . map ( ToString :: to_string) . collect ( )
84
85
}
85
86
86
87
/// Join a list of group members into a string separating each group name with a `,`.
87
- fn join_group_members ( v : & [ String ] ) -> String {
88
- v. join ( "," )
88
+ fn join_group_members ( v : & HashSet < String > ) -> String {
89
+ v. clone ( ) . into_iter ( ) . collect :: < Vec < _ > > ( ) . join ( "," )
89
90
}
90
91
91
92
#[ derive( Default ) ]
0 commit comments