pub const ARCH: &str;
A string describing the architecture of the CPU that is currently
2 | in use.
3 |
Some possible values:
4 |
5 | - x86
6 | - x86_64
7 | - arm
8 | - aarch64
9 | - mips
10 | - mips64
11 | - powerpc
12 | - powerpc64
13 | - riscv64
14 | - s390x
15 | - sparc64
16 |
17 |
1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
7 | 7
8 | 8
9 | 9
10 | 10
11 | 11
12 | 12
13 | 13
14 | 14
15 | 15
16 | 16
17 | 17
18 | 18
19 |
20 | use adler32::RollingAdler32;
21 |
22 | #[doc(hidden)]
23 | pub const MZ_ADLER32_INIT: u32 = 1;
24 |
25 | #[doc(hidden)]
26 | pub const MZ_DEFAULT_WINDOW_BITS: i32 = 15;
27 |
28 | pub const HUFFMAN_LENGTH_ORDER: [u8; 19] = [
29 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
30 | ];
31 |
32 | #[doc(hidden)]
33 | pub fn update_adler32(adler: u32, data: &[u8]) -> u32 {
34 | let mut hash = RollingAdler32::from_value(adler);
35 | hash.update_buffer(data);
36 | hash.hash()
37 | }
38 |
39 | pub trait AsRef<T> where
T: ?Sized, {
2 | fn as_ref(&self) -> &T;
3 | }
Used to do a cheap reference-to-reference conversion.
4 |
This trait is similar to AsMut
which is used for converting between mutable references.
5 | If you need to do a costly conversion it is better to implement From
with type
6 | &T
or write a custom function.
7 |
AsRef
has the same signature as Borrow
, but Borrow
is different in few aspects:
8 |
9 | - Unlike
AsRef
, Borrow
has a blanket impl for any T
, and can be used to accept either
10 | a reference or a value.
11 | Borrow
also requires that Hash
, Eq
and Ord
for borrowed value are
12 | equivalent to those of the owned value. For this reason, if you want to
13 | borrow only a single field of a struct you can implement AsRef
, but not Borrow
.
14 |
15 |
Note: This trait must not fail. If the conversion can fail, use a
16 | dedicated method which returns an Option<T>
or a Result<T, E>
.
17 |
18 |
19 | AsRef
auto-dereferences if the inner type is a reference or a mutable
20 | reference (e.g.: foo.as_ref()
will work the same if foo
has type
21 | &mut Foo
or &&mut Foo
)
22 |
23 |
24 |
By using trait bounds we can accept arguments of different types as long as they can be
25 | converted to the specified type T
.
26 |
For example: By creating a generic function that takes an AsRef<str>
we express that we
27 | want to accept all references that can be converted to &str
as an argument.
28 | Since both String
and &str
implement AsRef<str>
we can accept both as input argument.
29 |
30 |
31 | fn is_hello<T: AsRef<str>>(s: T) {
32 | assert_eq!("hello", s.as_ref());
33 | }
34 |
35 | let s = "hello";
36 | is_hello(s);
37 |
38 | let s = "hello".to_string();
39 | is_hello(s);
Run
40 |
41 | fn as_ref(&self) -> &T
Performs the conversion.
42 |
Loading content...
43 | impl<'_> AsRef<OsStr> for std::path::Iter<'_>
[src]
impl<'_> AsRef<Path> for std::path::Iter<'_>
[src]
impl<'_, T> AsRef<[T]> for std::slice::Iter<'_, T>
[src]
impl<'_, T> AsRef<T> for Cow<'_, T> where
T: ToOwned + ?Sized,
[src]
impl<'_, T, U> AsRef<U> for &'_ T where
T: AsRef<U> + ?Sized,
U: ?Sized,
[src]
impl<'_, T, U> AsRef<U> for &'_ mut T where
T: AsRef<U> + ?Sized,
U: ?Sized,
[src]
impl<T> AsRef<[T]> for [T]
[src]
impl<T> AsRef<[T]> for Vec<T>
[src]
impl<T> AsRef<Vec<T>> for Vec<T>
[src]
impl<T> AsRef<T> for Box<T> where
T: ?Sized,
[src]
impl<T> AsRef<T> for Rc<T> where
T: ?Sized,
[src]
impl<T> AsRef<T> for Arc<T> where
T: ?Sized,
[src]
Loading content...