1
1
use core:: { error, fmt} ;
2
2
use std:: collections:: { HashMap , HashSet } ;
3
- use std:: num:: ParseIntError ;
3
+ use std:: num:: { ParseIntError , TryFromIntError } ;
4
4
use std:: str:: FromStr ;
5
5
use std:: string:: FromUtf16Error ;
6
6
@@ -209,7 +209,6 @@ impl PartialEq<Account> for AccountWithId {
209
209
///
210
210
/// `LookupAccountNameW` must be called to enable `ConvertSidToStringSidW` to work.
211
211
#[ cfg( target_os = "windows" ) ]
212
- #[ allow( clippy:: cast_possible_truncation) ]
213
212
pub ( crate ) unsafe fn list_accounts ( ) -> Result < Vec < Account > , ListAccountsError > {
214
213
use windows:: core:: PWSTR ;
215
214
use windows:: Win32 :: NetworkManagement :: NetManagement :: {
@@ -255,9 +254,9 @@ pub(crate) unsafe fn list_accounts() -> Result<Vec<Account>, ListAccountsError>
255
254
// SAFETY: `user.usri0_name` is a valid string.
256
255
let name = unsafe { user. usri0_name . display ( ) } . to_string ( ) ;
257
256
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 ( ) ) ? ;
259
258
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 ( ) ) ? ;
261
260
let domain_name = PWSTR ( domain_name. as_mut_ptr ( ) ) ;
262
261
let mut sid_type = SID_NAME_USE ( 0 ) ;
263
262
let sid = PSID ( sid. as_mut_ptr ( ) . cast ( ) ) ;
@@ -405,6 +404,7 @@ pub(crate) fn diff_accounts(old: &[AccountWithId], new: &[Account]) -> AccountsD
405
404
pub enum ListAccountsError {
406
405
FromUtf16 ( FromUtf16Error ) ,
407
406
ParseSid ( ParseSidError ) ,
407
+ TryFromInt ( TryFromIntError ) ,
408
408
#[ cfg( target_os = "windows" ) ]
409
409
Windows ( windows_result:: Error ) ,
410
410
/// Contains `nStatus`.
@@ -416,6 +416,7 @@ impl error::Error for ListAccountsError {
416
416
match self {
417
417
Self :: FromUtf16 ( e) => Some ( e) ,
418
418
Self :: ParseSid ( e) => Some ( e) ,
419
+ Self :: TryFromInt ( e) => Some ( e) ,
419
420
#[ cfg( target_os = "windows" ) ]
420
421
Self :: Windows ( e) => Some ( e) ,
421
422
Self :: NetUserEnumFail ( _) => None ,
@@ -428,6 +429,7 @@ impl fmt::Display for ListAccountsError {
428
429
match self {
429
430
Self :: FromUtf16 ( e) => e. fmt ( f) ,
430
431
Self :: ParseSid ( e) => e. fmt ( f) ,
432
+ Self :: TryFromInt ( e) => e. fmt ( f) ,
431
433
#[ cfg( target_os = "windows" ) ]
432
434
Self :: Windows ( e) => e. fmt ( f) ,
433
435
Self :: NetUserEnumFail ( n) => {
@@ -447,6 +449,11 @@ impl From<ParseSidError> for ListAccountsError {
447
449
Self :: ParseSid ( e)
448
450
}
449
451
}
452
+ impl From < TryFromIntError > for ListAccountsError {
453
+ fn from ( e : TryFromIntError ) -> Self {
454
+ Self :: TryFromInt ( e)
455
+ }
456
+ }
450
457
#[ cfg( target_os = "windows" ) ]
451
458
impl From < windows_result:: Error > for ListAccountsError {
452
459
fn from ( e : windows_result:: Error ) -> Self {
0 commit comments