mirror of
https://github.com/openharmony/third_party_rust_libloading.git
synced 2026-07-19 21:23:39 -04:00
Replace try! with ?
`?` was stabilised in `1.13`, which is already below the minimum required Rust version. This gets rid of deprecation warnings.
This commit is contained in:
+2
-2
@@ -118,7 +118,7 @@ impl Library {
|
||||
where P: AsRef<OsStr> {
|
||||
let filename = match filename {
|
||||
None => None,
|
||||
Some(ref f) => Some(try!(cstr_cow_from_bytes(f.as_ref().as_bytes()))),
|
||||
Some(ref f) => Some(cstr_cow_from_bytes(f.as_ref().as_bytes())?),
|
||||
};
|
||||
with_dlerror(move || {
|
||||
let result = unsafe {
|
||||
@@ -149,7 +149,7 @@ impl Library {
|
||||
where F: FnOnce() -> ::Result<Symbol<T>>
|
||||
{
|
||||
ensure_compatible_types::<T, *mut raw::c_void>();
|
||||
let symbol = try!(cstr_cow_from_bytes(symbol));
|
||||
let symbol = cstr_cow_from_bytes(symbol)?;
|
||||
// `dlsym` may return nullptr in two cases: when a symbol genuinely points to a null
|
||||
// pointer or the symbol cannot be found. In order to detect this case a double dlerror
|
||||
// pattern must be used, which is, sadly, a little bit racy.
|
||||
|
||||
@@ -73,7 +73,7 @@ impl Library {
|
||||
/// definied behaviour.
|
||||
pub unsafe fn get<T>(&self, symbol: &[u8]) -> ::Result<Symbol<T>> {
|
||||
ensure_compatible_types::<T, FARPROC>();
|
||||
let symbol = try!(cstr_cow_from_bytes(symbol));
|
||||
let symbol = cstr_cow_from_bytes(symbol)?;
|
||||
with_get_last_error(|| {
|
||||
let symbol = libloaderapi::GetProcAddress(self.0, symbol.as_ptr());
|
||||
if symbol.is_null() {
|
||||
|
||||
+2
-2
@@ -42,9 +42,9 @@ pub fn cstr_cow_from_bytes<'a>(slice: &'a [u8]) -> Result<Cow<'a, CStr>, NullErr
|
||||
// Slice out of 0 elements
|
||||
None => unsafe { Cow::Borrowed(CStr::from_ptr(&ZERO)) },
|
||||
// Slice with trailing 0
|
||||
Some(&0) => Cow::Borrowed(try!(CStr::from_bytes_with_nul(slice))),
|
||||
Some(&0) => Cow::Borrowed(CStr::from_bytes_with_nul(slice)?),
|
||||
// Slice with no trailing 0
|
||||
Some(_) => Cow::Owned(try!(CString::new(slice))),
|
||||
Some(_) => Cow::Owned(CString::new(slice)?),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user