| 1 | //! Read and write DWARF's "Little Endian Base 128" (LEB128) variable length |
| 2 | //! integer encoding. |
| 3 | //! |
| 4 | //! The implementation is a direct translation of the psuedocode in the DWARF 4 |
| 5 | //! standard's appendix C. |
| 6 | //! |
| 7 | //! Read and write signed integers: |
| 8 | //! |
| 9 | //! ``` |
| 10 | //! use leb128; |
| 11 | //! |
| 12 | //! let mut buf = [0; 1024]; |
| 13 | //! |
| 14 | //! // Write to anything that implements `std::io::Write`. |
| 15 | //! { |
| 16 | //! let mut writable = &mut buf[..]; |
| 17 | //! leb128::write::signed(&mut writable, -12345).expect("Should write number"); |
| 18 | //! } |
| 19 | //! |
| 20 | //! // Read from anything that implements `std::io::Read`. |
| 21 | //! let mut readable = &buf[..]; |
| 22 | //! let val = leb128::read::signed(&mut readable).expect("Should read number"); |
| 23 | //! assert_eq!(val, -12345); |
| 24 | //! ``` |
| 25 | //! |
| 26 | //! Or read and write unsigned integers: |
| 27 | //! |
| 28 | //! ``` |
| 29 | //! use leb128; |
| 30 | //! |
| 31 | //! let mut buf = [0; 1024]; |
| 32 | //! |
| 33 | //! { |
| 34 | //! let mut writable = &mut buf[..]; |
| 35 | //! leb128::write::unsigned(&mut writable, 98765).expect("Should write number"); |
| 36 | //! } |
| 37 | //! |
| 38 | //! let mut readable = &buf[..]; |
| 39 | //! let val = leb128::read::unsigned(&mut readable).expect("Should read number"); |
| 40 | //! assert_eq!(val, 98765); |
| 41 | //! ``` |
| 42 | |
| 43 | #![deny(missing_docs)] |
| 44 | |
| 45 | #[doc(hidden)] |
| 46 | pub const CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.: u8 = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().7; |
| 47 | #[doc(hidden)] |
| 48 | pub const SIGN_BITrust-analyzer cargo leb128 0.2.5 SIGN_BIT.: u8 = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().6; |
| 49 | |
| 50 | #[doc(hidden)] |
| 51 | #[inline] |
| 52 | pub fn low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(byte: u8) -> u8 { |
| 53 | byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][Not]not().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. |
| 54 | } |
| 55 | |
| 56 | #[doc(hidden)] |
| 57 | #[inline] |
| 58 | pub fn low_bits_of_u64rust-analyzer cargo leb128 0.2.5 low_bits_of_u64().(val: u64) -> u8 { |
| 59 | let byte = val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::u8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u8/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u8/MAX. as u64); |
| 60 | low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(byte as u8) |
| 61 | } |
| 62 | |
| 63 | /// A module for reading LEB128-encoded signed and unsigned integers. |
| 64 | pub mod readrust-analyzer cargo leb128 0.2.5 read/ { |
| 65 | use superrust-analyzer cargo leb128 0.2.5 crate/::{low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte()., CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., SIGN_BITrust-analyzer cargo leb128 0.2.5 SIGN_BIT.}; |
| 66 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 67 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 68 | |
| 69 | /// An error type for reading LEB128-encoded values. |
| 70 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 71 | pub enum Errorrust-analyzer cargo leb128 0.2.5 read/Error# { |
| 72 | /// There was an underlying IO error. |
| 73 | IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 74 | /// The number being read is larger than can be represented. |
| 75 | Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow#, |
| 76 | } |
| 77 | |
| 78 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for Errorrust-analyzer cargo leb128 0.2.5 read/Error# { |
| 79 | fn fromrust-analyzer cargo leb128 0.2.5 read/impl#[Error][`From<io::Error>`]from().(e: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo leb128 0.2.5 read/impl#[Error][`From<io::Error>`] { |
| 80 | Errorrust-analyzer cargo leb128 0.2.5 read/Error#::IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(e) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo leb128 0.2.5 read/Error# { |
| 85 | fn fmtrust-analyzer cargo leb128 0.2.5 read/impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 86 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 87 | Errorrust-analyzer cargo leb128 0.2.5 read/Error#::IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(ref e) => e.fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][Display]fmt().(f), |
| 88 | Errorrust-analyzer cargo leb128 0.2.5 read/Error#::Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow# => { |
| 89 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "The number being read is larger than can be represented") |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo leb128 0.2.5 read/Error# { |
| 96 | fn sourcerust-analyzer cargo leb128 0.2.5 read/impl#[Error][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static)> { |
| 97 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 98 | Errorrust-analyzer cargo leb128 0.2.5 read/Error#::IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(ref e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e), |
| 99 | Errorrust-analyzer cargo leb128 0.2.5 read/Error#::Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /// Read an unsigned LEB128-encoded number from the `std::io::Read` stream |
| 105 | /// `r`. |
| 106 | /// |
| 107 | /// On success, return the number. |
| 108 | pub fn unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().<R>(r: &mut R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u64, Errorrust-analyzer cargo leb128 0.2.5 read/Error#> |
| 109 | where |
| 110 | R: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, |
| 111 | { |
| 112 | let mut result = 0; |
| 113 | let mut shift = 0; |
| 114 | |
| 115 | loop { |
| 116 | let mut buf = [0]; |
| 117 | r.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 118 | |
| 119 | if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().63 && buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0x00 && buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0x01 { |
| 120 | while buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 121 | r.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 122 | } |
| 123 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo leb128 0.2.5 read/Error#::Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow#); |
| 124 | } |
| 125 | |
| 126 | let low_bits = low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) as u64; |
| 127 | result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOrAssign<Self>`]bitor_assign().low_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().shift; |
| 128 | |
| 129 | if buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 130 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result); |
| 131 | } |
| 132 | |
| 133 | shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().7; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /// Read a signed LEB128-encoded number from the `std::io::Read` stream `r`. |
| 138 | /// |
| 139 | /// On success, return the number. |
| 140 | pub fn signedrust-analyzer cargo leb128 0.2.5 read/signed().<R>(r: &mut R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, Errorrust-analyzer cargo leb128 0.2.5 read/Error#> |
| 141 | where |
| 142 | R: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, |
| 143 | { |
| 144 | let mut result = 0; |
| 145 | let mut shift = 0; |
| 146 | let size = 64; |
| 147 | let mut byte; |
| 148 | |
| 149 | loop { |
| 150 | let mut buf = [0]; |
| 151 | r.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 152 | |
| 153 | byte = buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 154 | if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().63 && byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0x00 && byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0x7f { |
| 155 | while buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 156 | r.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 157 | } |
| 158 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo leb128 0.2.5 read/Error#::Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow#); |
| 159 | } |
| 160 | |
| 161 | let low_bits = low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(byte) as i64; |
| 162 | result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign().low_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl().shift; |
| 163 | shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().7; |
| 164 | |
| 165 | if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().size && (SIGN_BITrust-analyzer cargo leb128 0.2.5 SIGN_BIT. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().byte) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().SIGN_BITrust-analyzer cargo leb128 0.2.5 SIGN_BIT. { |
| 171 | // Sign extend the result. |
| 172 | result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`BitOrAssign<Self>`]bitor_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][Not]not().0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`Shl<i32>`]shl().shift; |
| 173 | } |
| 174 | |
| 175 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /// A module for writing LEB128-encoded signed and unsigned integers. |
| 180 | pub mod writerust-analyzer cargo leb128 0.2.5 write/ { |
| 181 | use superrust-analyzer cargo leb128 0.2.5 crate/::{low_bits_of_u64rust-analyzer cargo leb128 0.2.5 low_bits_of_u64()., CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.}; |
| 182 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 183 | |
| 184 | /// Write `val` to the `std::io::Write` stream `w` as an unsigned LEB128 value. |
| 185 | /// |
| 186 | /// On success, return the number of bytes written to `w`. |
| 187 | pub fn unsignedrust-analyzer cargo leb128 0.2.5 write/unsigned().<W>(w: &mut W, mut val: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> |
| 188 | where |
| 189 | W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 190 | { |
| 191 | let mut bytes_written = 0; |
| 192 | loop { |
| 193 | let mut byte = low_bits_of_u64rust-analyzer cargo leb128 0.2.5 low_bits_of_u64().(val); |
| 194 | val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<i32>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<i32>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<i32>`]shr_assign().7; |
| 195 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 { |
| 196 | // More bytes to come, so set the continuation bit. |
| 197 | byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.; |
| 198 | } |
| 199 | |
| 200 | let buf = [byte]; |
| 201 | w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 202 | bytes_written rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 203 | |
| 204 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 205 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes_written); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /// Write `val` to the `std::io::Write` stream `w` as a signed LEB128 value. |
| 211 | /// |
| 212 | /// On success, return the number of bytes written to `w`. |
| 213 | pub fn signedrust-analyzer cargo leb128 0.2.5 write/signed().<W>(w: &mut W, mut val: i64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> |
| 214 | where |
| 215 | W: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 216 | { |
| 217 | let mut bytes_written = 0; |
| 218 | loop { |
| 219 | let mut byte = val as u8; |
| 220 | // Keep the sign bit for testing |
| 221 | val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign().6; |
| 222 | let done = val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().0 || val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1; |
| 223 | if done { |
| 224 | byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][Not]not().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.; |
| 225 | } else { |
| 226 | // Remove the sign bit |
| 227 | val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i64][`ShrAssign<i32>`]shr_assign().1; |
| 228 | // More bytes to come, so set the continuation bit. |
| 229 | byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.; |
| 230 | } |
| 231 | |
| 232 | let buf = [byte]; |
| 233 | w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 234 | bytes_written rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 235 | |
| 236 | if done { |
| 237 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes_written); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | #[cfg(test)] |
| 244 | mod testsrust-analyzer cargo leb128 0.2.5 tests/ { |
| 245 | use superrust-analyzer cargo leb128 0.2.5 crate/::*; |
| 246 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/; |
| 247 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 248 | |
| 249 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 250 | fn test_low_bits_of_byterust-analyzer cargo leb128 0.2.5 tests/test_low_bits_of_byte().() { |
| 251 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127 { |
| 252 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(i)); |
| 253 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, low_bits_of_byterust-analyzer cargo leb128 0.2.5 low_bits_of_byte().(i |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.)); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 258 | fn test_low_bits_of_u64rust-analyzer cargo leb128 0.2.5 tests/test_low_bits_of_u64().() { |
| 259 | for i in 0u64..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127 { |
| 260 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i as u8, low_bits_of_u64rust-analyzer cargo leb128 0.2.5 low_bits_of_u64().(1 << 16 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). i)); |
| 261 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 262 | i as u8, |
| 263 | low_bits_of_u64rust-analyzer cargo leb128 0.2.5 low_bits_of_u64().(i << 16 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). i |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). (CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT. as u64)) |
| 264 | ); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Examples from the DWARF 4 standard, section 7.6, figure 22. |
| 269 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 270 | fn test_read_unsignedrust-analyzer cargo leb128 0.2.5 tests/test_read_unsigned().() { |
| 271 | let buf = [2u8]; |
| 272 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 273 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 274 | 2, |
| 275 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 276 | ); |
| 277 | |
| 278 | let buf = [127u8]; |
| 279 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 281 | 127, |
| 282 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 283 | ); |
| 284 | |
| 285 | let buf = [CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1]; |
| 286 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 287 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 288 | 128, |
| 289 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 290 | ); |
| 291 | |
| 292 | let buf = [1u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1]; |
| 293 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 294 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 295 | 129, |
| 296 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 297 | ); |
| 298 | |
| 299 | let buf = [2u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1]; |
| 300 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 301 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 302 | 130, |
| 303 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 304 | ); |
| 305 | |
| 306 | let buf = [57u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 100]; |
| 307 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 308 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 309 | 12857, |
| 310 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 311 | ); |
| 312 | } |
| 313 | |
| 314 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 315 | fn test_read_unsigned_thru_dyn_traitrust-analyzer cargo leb128 0.2.5 tests/test_read_unsigned_thru_dyn_trait().() { |
| 316 | fn readrust-analyzer cargo leb128 0.2.5 tests/read().(r: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#) -> u64 { |
| 317 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(r).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 318 | } |
| 319 | |
| 320 | let buf = [0u8]; |
| 321 | |
| 322 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 323 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(0, readrust-analyzer cargo leb128 0.2.5 tests/read().(&mut readable)); |
| 324 | |
| 325 | let mut readable = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(buf); |
| 326 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(0, readrust-analyzer cargo leb128 0.2.5 tests/read().(&mut readable)); |
| 327 | } |
| 328 | |
| 329 | // Examples from the DWARF 4 standard, section 7.6, figure 23. |
| 330 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 331 | fn test_read_signedrust-analyzer cargo leb128 0.2.5 tests/test_read_signed().() { |
| 332 | let buf = [2u8]; |
| 333 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 334 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(2, readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number")); |
| 335 | |
| 336 | let buf = [0x7eu8]; |
| 337 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 338 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().2, readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number")); |
| 339 | |
| 340 | let buf = [127u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 0]; |
| 341 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 342 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 343 | 127, |
| 344 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 345 | ); |
| 346 | |
| 347 | let buf = [1u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 0x7f]; |
| 348 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 349 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 350 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().127, |
| 351 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 352 | ); |
| 353 | |
| 354 | let buf = [CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1]; |
| 355 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 356 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 357 | 128, |
| 358 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 359 | ); |
| 360 | |
| 361 | let buf = [CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 0x7f]; |
| 362 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 363 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 364 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().128, |
| 365 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 366 | ); |
| 367 | |
| 368 | let buf = [1u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1]; |
| 369 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 370 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 371 | 129, |
| 372 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 373 | ); |
| 374 | |
| 375 | let buf = [0x7fu8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 0x7e]; |
| 376 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 377 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 378 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().129, |
| 379 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 380 | ); |
| 381 | } |
| 382 | |
| 383 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 384 | fn test_read_signed_thru_dyn_traitrust-analyzer cargo leb128 0.2.5 tests/test_read_signed_thru_dyn_trait().() { |
| 385 | fn readrust-analyzer cargo leb128 0.2.5 tests/read().(r: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#) -> i64 { |
| 386 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(r).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 387 | } |
| 388 | |
| 389 | let buf = [0u8]; |
| 390 | |
| 391 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 392 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(0, readrust-analyzer cargo leb128 0.2.5 tests/read().(&mut readable)); |
| 393 | |
| 394 | let mut readable = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(buf); |
| 395 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(0, readrust-analyzer cargo leb128 0.2.5 tests/read().(&mut readable)); |
| 396 | } |
| 397 | |
| 398 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 399 | fn test_read_signed_63_bitsrust-analyzer cargo leb128 0.2.5 tests/test_read_signed_63_bits().() { |
| 400 | let buf = [ |
| 401 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 402 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 403 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 404 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 405 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 406 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 407 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 408 | CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 409 | 0x40, |
| 410 | ]; |
| 411 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 412 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 413 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().0x4000000000000000, |
| 414 | readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read number") |
| 415 | ); |
| 416 | } |
| 417 | |
| 418 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 419 | fn test_read_unsigned_not_enough_datarust-analyzer cargo leb128 0.2.5 tests/test_read_unsigned_not_enough_data().() { |
| 420 | let buf = [CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.]; |
| 421 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 422 | match readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable) { |
| 423 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(readrust-analyzer cargo leb128 0.2.5 read/::Errorrust-analyzer cargo leb128 0.2.5 read/Error#::IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(e)) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#), |
| 424 | otherwise => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected: {:?}", otherwise), |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 429 | fn test_read_signed_not_enough_datarust-analyzer cargo leb128 0.2.5 tests/test_read_signed_not_enough_data().() { |
| 430 | let buf = [CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT.]; |
| 431 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 432 | match readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable) { |
| 433 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(readrust-analyzer cargo leb128 0.2.5 read/::Errorrust-analyzer cargo leb128 0.2.5 read/Error#::IoErrorrust-analyzer cargo leb128 0.2.5 read/Error#IoError#(e)) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#), |
| 434 | otherwise => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected: {:?}", otherwise), |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 439 | fn test_write_unsigned_not_enough_spacerust-analyzer cargo leb128 0.2.5 tests/test_write_unsigned_not_enough_space().() { |
| 440 | let mut buf = [0; 1]; |
| 441 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 442 | match writerust-analyzer cargo leb128 0.2.5 write/::unsignedrust-analyzer cargo leb128 0.2.5 write/unsigned().(&mut writable, 128) { |
| 443 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::WriteZerorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WriteZero#), |
| 444 | otherwise => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected: {:?}", otherwise), |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 449 | fn test_write_signed_not_enough_spacerust-analyzer cargo leb128 0.2.5 tests/test_write_signed_not_enough_space().() { |
| 450 | let mut buf = [0; 1]; |
| 451 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 452 | match writerust-analyzer cargo leb128 0.2.5 write/::signedrust-analyzer cargo leb128 0.2.5 write/signed().(&mut writable, 128) { |
| 453 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::WriteZerorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WriteZero#), |
| 454 | otherwise => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected: {:?}", otherwise), |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 459 | fn test_write_unsigned_thru_dyn_traitrust-analyzer cargo leb128 0.2.5 tests/test_write_unsigned_thru_dyn_trait().() { |
| 460 | fn writerust-analyzer cargo leb128 0.2.5 tests/write().(w: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, val: u64) -> usize { |
| 461 | writerust-analyzer cargo leb128 0.2.5 write/::unsignedrust-analyzer cargo leb128 0.2.5 write/unsigned().(w, val).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should write number") |
| 462 | } |
| 463 | let mut buf = [0u8; 1]; |
| 464 | |
| 465 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 466 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(writerust-analyzer cargo leb128 0.2.5 tests/write().(&mut writable, 0), 1); |
| 467 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 0); |
| 468 | |
| 469 | let mut writable = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`From<&[T]>`]from().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().); |
| 470 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(writerust-analyzer cargo leb128 0.2.5 tests/write().(&mut writable, 0), 1); |
| 471 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 0); |
| 472 | } |
| 473 | |
| 474 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 475 | fn test_write_signed_thru_dyn_traitrust-analyzer cargo leb128 0.2.5 tests/test_write_signed_thru_dyn_trait().() { |
| 476 | fn writerust-analyzer cargo leb128 0.2.5 tests/write().(w: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, val: i64) -> usize { |
| 477 | writerust-analyzer cargo leb128 0.2.5 write/::signedrust-analyzer cargo leb128 0.2.5 write/signed().(w, val).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should write number") |
| 478 | } |
| 479 | let mut buf = [0u8; 1]; |
| 480 | |
| 481 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 482 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(writerust-analyzer cargo leb128 0.2.5 tests/write().(&mut writable, 0), 1); |
| 483 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 0); |
| 484 | |
| 485 | let mut writable = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`From<&[T]>`]from().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().); |
| 486 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(writerust-analyzer cargo leb128 0.2.5 tests/write().(&mut writable, 0), 1); |
| 487 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 0); |
| 488 | } |
| 489 | |
| 490 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 491 | fn dogfood_signedrust-analyzer cargo leb128 0.2.5 tests/dogfood_signed().() { |
| 492 | fn innerrust-analyzer cargo leb128 0.2.5 tests/inner().(i: i64) { |
| 493 | let mut buf = [0u8; 1024]; |
| 494 | |
| 495 | { |
| 496 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 497 | writerust-analyzer cargo leb128 0.2.5 write/::signedrust-analyzer cargo leb128 0.2.5 write/signed().(&mut writable, i).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should write signed number"); |
| 498 | } |
| 499 | |
| 500 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 501 | let result = readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should be able to read it back again"); |
| 502 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, result); |
| 503 | } |
| 504 | for i in -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().513..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#513 { |
| 505 | innerrust-analyzer cargo leb128 0.2.5 tests/inner().(i); |
| 506 | } |
| 507 | innerrust-analyzer cargo leb128 0.2.5 tests/inner().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::i64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/i64/::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/i64/MIN.); |
| 508 | } |
| 509 | |
| 510 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 511 | fn dogfood_unsignedrust-analyzer cargo leb128 0.2.5 tests/dogfood_unsigned().() { |
| 512 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1025 { |
| 513 | let mut buf = [0u8; 1024]; |
| 514 | |
| 515 | { |
| 516 | let mut writable = &mut buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().; |
| 517 | writerust-analyzer cargo leb128 0.2.5 write/::unsignedrust-analyzer cargo leb128 0.2.5 write/unsigned().(&mut writable, i).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should write signed number"); |
| 518 | } |
| 519 | |
| 520 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 521 | let result = |
| 522 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should be able to read it back again"); |
| 523 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, result); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 528 | fn test_read_unsigned_overflowrust-analyzer cargo leb128 0.2.5 tests/test_read_unsigned_overflow().() { |
| 529 | let buf = [ |
| 530 | 2u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 531 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 532 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 533 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 534 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 535 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 536 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 537 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 538 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 539 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 540 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 541 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 542 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 543 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 544 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 545 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 546 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 547 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 548 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 549 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 550 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 551 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 552 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 553 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 554 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 555 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 556 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 557 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 558 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 559 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 560 | 1, |
| 561 | ]; |
| 562 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 563 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 564 | } |
| 565 | |
| 566 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 567 | fn test_read_signed_overflowrust-analyzer cargo leb128 0.2.5 tests/test_read_signed_overflow().() { |
| 568 | let buf = [ |
| 569 | 2u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 570 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 571 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 572 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 573 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 574 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 575 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 576 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 577 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 578 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 579 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 580 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 581 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 582 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 583 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 584 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 585 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 586 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 587 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 588 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 589 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 590 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 591 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 592 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 593 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 594 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 595 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 596 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 597 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 598 | 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., |
| 599 | 1, |
| 600 | ]; |
| 601 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 602 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(readrust-analyzer cargo leb128 0.2.5 read/::signedrust-analyzer cargo leb128 0.2.5 read/signed().(&mut readable).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 603 | } |
| 604 | |
| 605 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 606 | fn test_read_multiplerust-analyzer cargo leb128 0.2.5 tests/test_read_multiple().() { |
| 607 | let buf = [2u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().CONTINUATION_BITrust-analyzer cargo leb128 0.2.5 CONTINUATION_BIT., 1u8, 1u8]; |
| 608 | |
| 609 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 610 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 611 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read first number"), |
| 612 | 130u64 |
| 613 | ); |
| 614 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 615 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should read first number"), |
| 616 | 1u64 |
| 617 | ); |
| 618 | } |
| 619 | |
| 620 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 621 | fn test_read_multiple_with_overflowrust-analyzer cargo leb128 0.2.5 tests/test_read_multiple_with_overflow().() { |
| 622 | let buf = [ |
| 623 | 0b1111_1111, |
| 624 | 0b1111_1111, |
| 625 | 0b1111_1111, |
| 626 | 0b1111_1111, |
| 627 | 0b1111_1111, |
| 628 | 0b1111_1111, |
| 629 | 0b1111_1111, |
| 630 | 0b1111_1111, |
| 631 | 0b1111_1111, |
| 632 | 0b1111_1111, |
| 633 | 0b0111_1111, // Overflow! |
| 634 | 0b1110_0100, |
| 635 | 0b1110_0000, |
| 636 | 0b0000_0010, // 45156 |
| 637 | ]; |
| 638 | let mut readable = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 639 | |
| 640 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(if let readrust-analyzer cargo leb128 0.2.5 read/::Errorrust-analyzer cargo leb128 0.2.5 read/Error#::Overflowrust-analyzer cargo leb128 0.2.5 read/Error#Overflow# = |
| 641 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail with Error::Overflow") |
| 642 | { |
| 643 | true |
| 644 | } else { |
| 645 | false |
| 646 | }); |
| 647 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 648 | readrust-analyzer cargo leb128 0.2.5 read/::unsignedrust-analyzer cargo leb128 0.2.5 read/unsigned().(&mut readable).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should succeed with correct value"), |
| 649 | 45156 |
| 650 | ); |
| 651 | } |
| 652 | } |