Debian Codegraph @

src/util.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/;
4
5 use craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#;
6
7 /// Checks for the last byte and avoids allocating if it is zero.
8 ///
9 /// Non-last null bytes still result in an error.
10 pub(craterust-analyzer cargo libloading 0.8.9 crate/) fn cstr_cow_from_bytesrust-analyzer cargo libloading 0.8.9 util/cstr_cow_from_bytes().(slice: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>, Errorrust-analyzer cargo libloading 0.8.9 error/Error#> {
11 static ZEROrust-analyzer cargo libloading 0.8.9 util/ZERO.: rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char# = 0;
12 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match slice.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() {
13 // Slice out of 0 elements
14 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => unsafe { Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(&ZEROrust-analyzer cargo libloading 0.8.9 util/ZERO.)) },
15 // Slice with trailing 0
16 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&0) => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(
17 CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_bytes_with_nulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_bytes_with_nul().(slice)
18 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|source| Errorrust-analyzer cargo libloading 0.8.9 error/Error#::CreateCStringWithTrailingrust-analyzer cargo libloading 0.8.9 error/Error#CreateCStringWithTrailing# { sourcerust-analyzer cargo libloading 0.8.9 error/Error#CreateCStringWithTrailing#source. })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
19 ),
20 // Slice with no trailing 0
21 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => {
22 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(slice).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|source| Errorrust-analyzer cargo libloading 0.8.9 error/Error#::CreateCStringrust-analyzer cargo libloading 0.8.9 error/Error#CreateCString# { sourcerust-analyzer cargo libloading 0.8.9 error/Error#CreateCString#source. })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
23 }
24 })
25 }
26
27 #[inline]
28 pub(craterust-analyzer cargo libloading 0.8.9 crate/) fn ensure_compatible_typesrust-analyzer cargo libloading 0.8.9 util/ensure_compatible_types().<T, E>() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo libloading 0.8.9 error/Error#> {
29 if ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<E>() {
30 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo libloading 0.8.9 error/Error#::IncompatibleSizerust-analyzer cargo libloading 0.8.9 error/Error#IncompatibleSize#)
31 } else {
32 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
33 }
34 }