From a412ef7c20d7dc61270ecb8822235316c2c1a3af Mon Sep 17 00:00:00 2001 From: Youyuan Wu Date: Tue, 21 Jan 2025 20:51:50 -0800 Subject: [PATCH] change get_stats to return Result --- src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7caf0dde76..b347928121 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1532,7 +1532,7 @@ impl Connection { } } - pub fn get_stats(&self) -> QuicStatistics { + pub fn get_stats(&self) -> Result { let mut stat_buffer: [u8; std::mem::size_of::()] = [0; std::mem::size_of::()]; let stat_size_mut = std::mem::size_of::(); @@ -1543,12 +1543,11 @@ impl Connection { (&stat_size_mut) as *const usize as *const u32 as *mut u32, stat_buffer.as_mut_ptr() as *mut c_void, ) - } - .expect("fail to get stats"); - unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatistics) } + }?; + Ok(unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatistics) }) } - pub fn get_stats_v2(&self) -> QuicStatisticsV2 { + pub fn get_stats_v2(&self) -> Result { let mut stat_buffer: [u8; std::mem::size_of::()] = [0; std::mem::size_of::()]; let stat_size_mut = std::mem::size_of::(); @@ -1559,10 +1558,8 @@ impl Connection { (&stat_size_mut) as *const usize as *const u32 as *mut u32, stat_buffer.as_mut_ptr() as *mut c_void, ) - } - .expect("fail to get stats v2"); - - unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatisticsV2) } + }?; + Ok(unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatisticsV2) }) } pub fn set_configuration(&self, configuration: &Configuration) -> Result<(), Error> {