11use core:: { error, fmt} ;
22use std:: collections:: { HashMap , HashSet } ;
3- use std:: num:: ParseIntError ;
3+ use std:: num:: { ParseIntError , TryFromIntError } ;
44use std:: str:: FromStr ;
55use std:: string:: FromUtf16Error ;
66
@@ -209,7 +209,6 @@ impl PartialEq<Account> for AccountWithId {
209209///
210210/// `LookupAccountNameW` must be called to enable `ConvertSidToStringSidW` to work.
211211#[ cfg( target_os = "windows" ) ]
212- #[ allow( clippy:: cast_possible_truncation) ]
213212pub ( crate ) unsafe fn list_accounts ( ) -> Result < Vec < Account > , ListAccountsError > {
214213 use windows:: core:: PWSTR ;
215214 use windows:: Win32 :: NetworkManagement :: NetManagement :: {
@@ -255,9 +254,9 @@ pub(crate) unsafe fn list_accounts() -> Result<Vec<Account>, ListAccountsError>
255254 // SAFETY: `user.usri0_name` is a valid string.
256255 let name = unsafe { user. usri0_name . display ( ) } . to_string ( ) ;
257256 let mut sid = [ 0u8 ; SECURITY_MAX_SID_SIZE as usize ] ;
258- let mut sid_size = sid. len ( ) as u32 ;
257+ let mut sid_size = u32 :: try_from ( sid. len ( ) ) ? ;
259258 let mut domain_name = [ 0u16 ; 256 ] ;
260- let mut domain_size = domain_name. len ( ) as u32 ;
259+ let mut domain_size = u32 :: try_from ( domain_name. len ( ) ) ? ;
261260 let domain_name = PWSTR ( domain_name. as_mut_ptr ( ) ) ;
262261 let mut sid_type = SID_NAME_USE ( 0 ) ;
263262 let sid = PSID ( sid. as_mut_ptr ( ) . cast ( ) ) ;
@@ -405,6 +404,7 @@ pub(crate) fn diff_accounts(old: &[AccountWithId], new: &[Account]) -> AccountsD
405404pub enum ListAccountsError {
406405 FromUtf16 ( FromUtf16Error ) ,
407406 ParseSid ( ParseSidError ) ,
407+ TryFromInt ( TryFromIntError ) ,
408408 #[ cfg( target_os = "windows" ) ]
409409 Windows ( windows_result:: Error ) ,
410410 /// Contains `nStatus`.
@@ -416,6 +416,7 @@ impl error::Error for ListAccountsError {
416416 match self {
417417 Self :: FromUtf16 ( e) => Some ( e) ,
418418 Self :: ParseSid ( e) => Some ( e) ,
419+ Self :: TryFromInt ( e) => Some ( e) ,
419420 #[ cfg( target_os = "windows" ) ]
420421 Self :: Windows ( e) => Some ( e) ,
421422 Self :: NetUserEnumFail ( _) => None ,
@@ -428,6 +429,7 @@ impl fmt::Display for ListAccountsError {
428429 match self {
429430 Self :: FromUtf16 ( e) => e. fmt ( f) ,
430431 Self :: ParseSid ( e) => e. fmt ( f) ,
432+ Self :: TryFromInt ( e) => e. fmt ( f) ,
431433 #[ cfg( target_os = "windows" ) ]
432434 Self :: Windows ( e) => e. fmt ( f) ,
433435 Self :: NetUserEnumFail ( n) => {
@@ -447,6 +449,11 @@ impl From<ParseSidError> for ListAccountsError {
447449 Self :: ParseSid ( e)
448450 }
449451}
452+ impl From < TryFromIntError > for ListAccountsError {
453+ fn from ( e : TryFromIntError ) -> Self {
454+ Self :: TryFromInt ( e)
455+ }
456+ }
450457#[ cfg( target_os = "windows" ) ]
451458impl From < windows_result:: Error > for ListAccountsError {
452459 fn from ( e : windows_result:: Error ) -> Self {
0 commit comments