| 1 | use craterust-analyzer cargo bitarray 0.10.0 crate/::BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#; |
| 2 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 3 | use serderust-analyzer cargo serde 1.0.229 crate/::{ |
| 4 | derust-analyzer cargo serde_core 1.0.229 de/::{Errorrust-analyzer cargo serde_core 1.0.229 de/Error#, Expectedrust-analyzer cargo serde_core 1.0.229 de/Expected#, SeqAccessrust-analyzer cargo serde_core 1.0.229 de/SeqAccess#, Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#}, |
| 5 | Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#, |
| 6 | }; |
| 7 | |
| 8 | impl<const B: usize> Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#<B> { |
| 9 | fn serializerust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArray<B>`][Serialize]serialize().<S>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> |
| 10 | where |
| 11 | S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#, |
| 12 | { |
| 13 | serializer.serialize_bytesrust-analyzer cargo serde_core 1.0.229 ser/Serializer#serialize_bytes().(&self.bytesrust-analyzer cargo bitarray 0.10.0 BitArray#bytes.) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl<'de, const B: usize> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#<B> { |
| 18 | fn deserializerust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArray<B>`][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArray<B>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> |
| 19 | where |
| 20 | D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>, |
| 21 | { |
| 22 | deserializer.deserialize_bytesrust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_bytes().(BitArrayVisitorrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayVisitor#::<B>) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | struct BitArrayVisitorrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayVisitor#<const B: usize>; |
| 27 | |
| 28 | impl<'de, const B: usize> Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#<'de> for BitArrayVisitorrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayVisitor#<B> { |
| 29 | type Valuerust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]Value# = BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#<B>; |
| 30 | |
| 31 | fn expectingrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]expecting().(&self, formatter: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 32 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "[u8; {}]", B) |
| 33 | } |
| 34 | |
| 35 | fn visit_seqrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]visit_seq().<A>(self, mut seq: A) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.229 de/Visitor#Value#, A::Errorrust-analyzer cargo serde_core 1.0.229 de/SeqAccess#Error#> |
| 36 | where |
| 37 | A: SeqAccessrust-analyzer cargo serde_core 1.0.229 de/SeqAccess#<'de>, |
| 38 | { |
| 39 | let mut arr = [0u8; B]; |
| 40 | let mut ix = 0; |
| 41 | // Continuously fill the array with more values. |
| 42 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = seq.next_elementrust-analyzer cargo serde_core 1.0.229 de/SeqAccess#next_element().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 43 | if ix rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().B { |
| 44 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::customrust-analyzer cargo serde_core 1.0.229 de/Error#custom().("bitarray: too many bytes in sequence")); |
| 45 | } |
| 46 | arr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().ix]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = value; |
| 47 | ix 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; |
| 48 | } |
| 49 | |
| 50 | if ix rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().B { |
| 51 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::invalid_lengthrust-analyzer cargo serde_core 1.0.229 de/Error#invalid_length().(ix, &BitArrayExpectedBytesrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayExpectedBytes#::<B>)) |
| 52 | } else { |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#::newrust-analyzer cargo bitarray 0.10.0 impl#[`BitArray<B>`]new().(arr)) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | fn visit_bytesrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]visit_bytes().<E>(self, bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayVisitor<B>`][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.229 de/Visitor#Value#, E> |
| 58 | where |
| 59 | E: Errorrust-analyzer cargo serde_core 1.0.229 de/Error#, |
| 60 | { |
| 61 | if bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().B { |
| 62 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::invalid_lengthrust-analyzer cargo serde_core 1.0.229 de/Error#invalid_length().( |
| 63 | bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 64 | &BitArrayExpectedBytesrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayExpectedBytes#::<B>, |
| 65 | )) |
| 66 | } else { |
| 67 | let mut bitarray = BitArrayrust-analyzer cargo bitarray 0.10.0 BitArray#::<B>::zerosrust-analyzer cargo bitarray 0.10.0 impl#[`BitArray<B>`]zeros().(); |
| 68 | bitarray.bytesrust-analyzer cargo bitarray 0.10.0 BitArray#bytes..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(bytes); |
| 69 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bitarray) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | struct BitArrayExpectedBytesrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayExpectedBytes#<const B: usize>; |
| 75 | |
| 76 | impl<const B: usize> Expectedrust-analyzer cargo serde_core 1.0.229 de/Expected# for BitArrayExpectedBytesrust-analyzer cargo bitarray 0.10.0 serde_impl/BitArrayExpectedBytes#<B> { |
| 77 | fn fmtrust-analyzer cargo bitarray 0.10.0 serde_impl/impl#[`BitArrayExpectedBytes<B>`][Expected]fmt().(&self, formatter: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 78 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "{} bytes", B) |
| 79 | } |
| 80 | } |