| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#; |
| 2 | 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/; |
| 3 | |
| 4 | use craterust-analyzer cargo serde_cbor_2 0.13.0 crate/::valuerust-analyzer cargo serde_cbor_2 0.13.0 value/::Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#; |
| 5 | use serderust-analyzer cargo serde 1.0.144 crate/::derust-analyzer cargo serde 1.0.144 de/; |
| 6 | |
| 7 | impl<'de> derust-analyzer cargo serde 1.0.144 de/::Deserializerust-analyzer cargo serde 1.0.144 de/Deserialize#<'de> for Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value# { |
| 8 | #[inline] |
| 9 | fn deserializerust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[Value][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#, D::Errorrust-analyzer cargo serde 1.0.144 de/Deserializer#Error#> |
| 10 | where |
| 11 | D: derust-analyzer cargo serde 1.0.144 de/::Deserializerrust-analyzer cargo serde 1.0.144 de/Deserializer#<'de>, |
| 12 | { |
| 13 | struct ValueVisitorrust-analyzer cargo serde_cbor_2 0.13.0 value/de/ValueVisitor#; |
| 14 | |
| 15 | impl<'de> derust-analyzer cargo serde 1.0.144 de/::Visitorrust-analyzer cargo serde 1.0.144 de/Visitor#<'de> for ValueVisitorrust-analyzer cargo serde_cbor_2 0.13.0 value/de/ValueVisitor# { |
| 16 | type Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]Value# = Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#; |
| 17 | |
| 18 | fn expectingrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]expecting().(&self, fmt: &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#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 19 | fmt.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("any valid CBOR value") |
| 20 | } |
| 21 | |
| 22 | #[inline] |
| 23 | fn visit_strrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_str().<E>(self, value: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#, E> |
| 24 | where |
| 25 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 26 | { |
| 27 | self.visit_stringrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_string().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(value)) |
| 28 | } |
| 29 | |
| 30 | #[inline] |
| 31 | fn visit_stringrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_string().<E>(self, value: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#, E> |
| 32 | where |
| 33 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 34 | { |
| 35 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#(value)) |
| 36 | } |
| 37 | #[inline] |
| 38 | fn visit_bytesrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_bytes().<E>(self, v: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 39 | where |
| 40 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 41 | { |
| 42 | self.visit_byte_bufrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_byte_buf().(v.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`][ToOwned]to_owned().()) |
| 43 | } |
| 44 | |
| 45 | #[inline] |
| 46 | fn visit_byte_bufrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_byte_buf().<E>(self, v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 47 | where |
| 48 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 49 | { |
| 50 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Bytesrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Bytes#(v)) |
| 51 | } |
| 52 | |
| 53 | #[inline] |
| 54 | fn visit_u64rust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_u64().<E>(self, v: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 55 | where |
| 56 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 57 | { |
| 58 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 59 | } |
| 60 | |
| 61 | #[inline] |
| 62 | fn visit_i64rust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_i64().<E>(self, v: i64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 63 | where |
| 64 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 65 | { |
| 66 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 67 | } |
| 68 | |
| 69 | #[inline] |
| 70 | fn visit_i128rust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_i128().<E>(self, v: i128) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 71 | where |
| 72 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 73 | { |
| 74 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(v)) |
| 75 | } |
| 76 | |
| 77 | #[inline] |
| 78 | fn visit_boolrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_bool().<E>(self, v: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 79 | where |
| 80 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 81 | { |
| 82 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Boolrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Bool#(v)) |
| 83 | } |
| 84 | |
| 85 | #[inline] |
| 86 | fn visit_nonerust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_none().<E>(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 87 | where |
| 88 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 89 | { |
| 90 | self.visit_unitrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_unit().() |
| 91 | } |
| 92 | |
| 93 | #[inline] |
| 94 | fn visit_unitrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_unit().<E>(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 95 | where |
| 96 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 97 | { |
| 98 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Nullrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Null#) |
| 99 | } |
| 100 | |
| 101 | #[inline] |
| 102 | fn visit_seqrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_seq().<V>(self, mut visitor: V) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, V::Errorrust-analyzer cargo serde 1.0.144 de/SeqAccess#Error#> |
| 103 | where |
| 104 | V: derust-analyzer cargo serde 1.0.144 de/::SeqAccessrust-analyzer cargo serde 1.0.144 de/SeqAccess#<'de>, |
| 105 | { |
| 106 | let mut vec = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 107 | |
| 108 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elem) = visitor.next_elementrust-analyzer cargo serde 1.0.144 de/SeqAccess#next_element().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 109 | vec.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(elem); |
| 110 | } |
| 111 | |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Arrayrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Array#(vec)) |
| 113 | } |
| 114 | |
| 115 | #[inline] |
| 116 | fn visit_maprust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_map().<V>(self, mut visitor: V) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#, V::Errorrust-analyzer cargo serde 1.0.144 de/MapAccess#Error#> |
| 117 | where |
| 118 | V: derust-analyzer cargo serde 1.0.144 de/::MapAccessrust-analyzer cargo serde 1.0.144 de/MapAccess#<'de>, |
| 119 | { |
| 120 | let mut values = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(); |
| 121 | |
| 122 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((key, value)) = visitor.next_entryrust-analyzer cargo serde 1.0.144 de/MapAccess#next_entry().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 123 | values.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(key, value); |
| 124 | } |
| 125 | |
| 126 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Maprust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Map#(values)) |
| 127 | } |
| 128 | |
| 129 | #[inline] |
| 130 | fn visit_f64rust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_f64().<E>(self, v: f64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, E> |
| 131 | where |
| 132 | E: derust-analyzer cargo serde 1.0.144 de/::Errorrust-analyzer cargo serde 1.0.144 de/Error#, |
| 133 | { |
| 134 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Floatrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Float#(v)) |
| 135 | } |
| 136 | |
| 137 | fn visit_newtype_structrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]visit_newtype_struct().<D>(self, deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo serde_cbor_2 0.13.0 value/de/impl#[ValueVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde 1.0.144 de/Visitor#Value#, D::Errorrust-analyzer cargo serde 1.0.144 de/Deserializer#Error#> |
| 138 | where |
| 139 | D: serderust-analyzer cargo serde 1.0.144 crate/::Deserializerrust-analyzer cargo serde 1.0.144 de/Deserializer#<'de>, |
| 140 | { |
| 141 | let tag = craterust-analyzer cargo serde_cbor_2 0.13.0 crate/::tagsrust-analyzer cargo serde_cbor_2 0.13.0 tags/::get_tagrust-analyzer cargo serde_cbor_2 0.13.0 tags/get_tag().(); |
| 142 | let inner = deserializer.deserialize_anyrust-analyzer cargo serde 1.0.144 de/Deserializer#deserialize_any().(self); |
| 143 | match tag { |
| 144 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag) => inner.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|v| Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Tagrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Tag#(tag, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(v))), |
| 145 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => inner, |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | deserializer.deserialize_anyrust-analyzer cargo serde 1.0.144 de/Deserializer#deserialize_any().(ValueVisitorrust-analyzer cargo serde_cbor_2 0.13.0 value/de/ValueVisitor#) |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /// Convert a `serde_cbor::Value` into a type `T` |
| 155 | #[allow(clippy::needless_pass_by_value)] |
| 156 | pub fn from_valuerust-analyzer cargo serde_cbor_2 0.13.0 value/de/from_value().<T>(value: Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, craterust-analyzer cargo serde_cbor_2 0.13.0 crate/::errorrust-analyzer cargo serde_cbor_2 0.13.0 error/::Errorrust-analyzer cargo serde_cbor_2 0.13.0 error/Error#> |
| 157 | where |
| 158 | T: derust-analyzer cargo serde 1.0.144 de/::DeserializeOwnedrust-analyzer cargo serde 1.0.144 de/DeserializeOwned#, |
| 159 | { |
| 160 | // TODO implement in a way that doesn't require |
| 161 | // roundtrip through buffer (i.e. by implementing |
| 162 | // `serde::de::Deserializer` for `Value` and then doing |
| 163 | // `T::deserialize(value)`). |
| 164 | let buf = craterust-analyzer cargo serde_cbor_2 0.13.0 crate/::to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 165 | craterust-analyzer cargo serde_cbor_2 0.13.0 crate/::from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(buf.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()) |
| 166 | } |