Debian Codegraph @

src/value/raw.rs

raw symbols SCIP
1 // Inspired by David Tolnay's serde-rs
2 // https://github.com/serde-rs/json/blob/master/src/raw.rs
3 // Licensed under either of Apache License, Version 2.0 or MIT license at your option.
4
5 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#, boxedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/::Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#, formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!, stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#};
6 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/, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#};
7
8 use serderust-analyzer cargo serde 1.0.228 crate/::{derust-analyzer cargo serde_core 1.0.228 de/, serrust-analyzer cargo serde_core 1.0.228 ser/, Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#};
9
10 use craterust-analyzer cargo ron 0.12.0 crate/::{
11 errorrust-analyzer cargo ron 0.12.0 error/::{Errorrust-analyzer cargo ron 0.12.0 error/Error#, SpannedResultrust-analyzer cargo ron 0.12.0 error/SpannedResult#},
12 optionsrust-analyzer cargo ron 0.12.0 options/::Optionsrust-analyzer cargo ron 0.12.0 options/Options#,
13 };
14
15 // NOTE: Keep synchronised with fuzz/arbitrary::typed_data::RAW_VALUE_TOKEN
16 pub(craterust-analyzer cargo ron 0.12.0 crate/) const RAW_VALUE_TOKENrust-analyzer cargo ron 0.12.0 value/raw/RAW_VALUE_TOKEN.: &str = "$ron::private::RawValue";
17
18 #[allow(clippy::module_name_repetitions)]
19 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
20 #[repr(transparent)]
21 pub struct RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
22 ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.: str,
23 }
24
25 #[allow(unsafe_code)]
26 impl RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
27 fn from_borrowed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_borrowed_str().(ron: &str) -> &Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue] {
28 // Safety: RawValue is a transparent newtype around str
29 unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(ron as *const str as *const RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#) }
30 }
31
32 fn from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(ron: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]> {
33 // Safety: RawValue is a transparent newtype around str
34 unsafe { corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>>(ron) }
35 }
36
37 fn into_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]into_boxed_str().(raw_value: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str> {
38 // Safety: RawValue is a transparent newtype around str
39 unsafe { corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>>(raw_value) }
40 }
41
42 #[allow(clippy::expect_used)]
43 fn trim_rangerust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]trim_range().(ron: &str) -> Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> {
44 fn trim_range_innerrust-analyzer cargo ron 0.12.0 value/raw/trim_range_inner().(ron: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>, Errorrust-analyzer cargo ron 0.12.0 error/Error#> {
45 let mut deserializer = craterust-analyzer cargo ron 0.12.0 crate/::Deserializerrust-analyzer cargo ron 0.12.0 de/Deserializer#::from_strrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]from_str().(ron).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo ron 0.12.0 error/Error#::fromrust-analyzer cargo ron 0.12.0 error/impl#[Error][`From<SpannedError>`]from().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46
47 deserializer.parserrust-analyzer cargo ron 0.12.0 de/Deserializer#parser..skip_wsrust-analyzer cargo ron 0.12.0 parse/impl#[`Parser<'a>`]skip_ws().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
48 let start_offset = ron.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().deserializer.parserrust-analyzer cargo ron 0.12.0 de/Deserializer#parser..srcrust-analyzer cargo ron 0.12.0 parse/impl#[`Parser<'a>`]src().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
49
50 let _ = serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::IgnoredAnyrust-analyzer cargo serde_core 1.0.228 de/ignored_any/IgnoredAny#::deserializerust-analyzer cargo serde_core 1.0.228 de/ignored_any/impl#[IgnoredAny][`Deserialize<'de>`]deserialize().(&mut deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
51
52 deserializer.parserrust-analyzer cargo ron 0.12.0 de/Deserializer#parser..skip_wsrust-analyzer cargo ron 0.12.0 parse/impl#[`Parser<'a>`]skip_ws().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
53 let end_offset = deserializer.parserrust-analyzer cargo ron 0.12.0 de/Deserializer#parser..pre_ws_srcrust-analyzer cargo ron 0.12.0 parse/impl#[`Parser<'a>`]pre_ws_src().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
54
55 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(start_offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(ron.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().end_offset))
56 }
57
58 trim_range_innerrust-analyzer cargo ron 0.12.0 value/raw/trim_range_inner().(ron).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("RawValue must contain valid ron")
59 }
60 }
61
62 impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#> {
63 fn clonerust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<RawValue>`][Clone]clone().(&self) -> Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<RawValue>`][Clone] {
64 (*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).to_ownedrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][ToOwned]to_owned().()
65 }
66 }
67
68 impl ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned# for RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
69 type Ownedrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][ToOwned]Owned# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>;
70
71 fn to_ownedrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][ToOwned]to_owned().(&self) -> Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][ToOwned]::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#Owned# {
72 RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().().into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().())
73 }
74 }
75
76 impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
77 fn fmtrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][Debug]fmt().(&self, f: &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 f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("RawValue")
79 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(&format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("{}", &self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.))
80 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().()
81 }
82 }
83
84 impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
85 fn fmtrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][Display]fmt().(&self, f: &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# {
86 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.)
87 }
88 }
89
90 impl RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
91 /// Get the inner raw RON string, which is guaranteed to contain valid RON.
92 #[must_use]
93 pub fn get_ronrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]get_ron().(&self) -> &str {
94 &self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.
95 }
96
97 /// Helper function to validate a RON string and turn it into a
98 /// [`RawValue`].
99 pub fn from_ronrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_ron().(ron: &str) -> SpannedResultrust-analyzer cargo ron 0.12.0 error/SpannedResult#<&Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]> {
100 let mut deserializer = craterust-analyzer cargo ron 0.12.0 crate/::Deserializerrust-analyzer cargo ron 0.12.0 de/Deserializer#::from_strrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]from_str().(ron)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
101
102 // raw values can be used everywhere but extensions cannot
103 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().deserializer.extensionsrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]extensions().().is_emptyrust-analyzer cargo ron 0.12.0 extensions/impl#[Extensions]is_empty().() {
104 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(deserializer.span_errorrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]span_error().(Errorrust-analyzer cargo ron 0.12.0 error/Error#::Messagerust-analyzer cargo ron 0.12.0 error/Error#Message#(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().(
105 "ron::value::RawValue cannot enable extensions",
106 ))));
107 }
108
109 let _ = <&Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]>::deserializerust-analyzer cargo ron 0.12.0 value/raw/impl#[`&'a RawValue`][`Deserialize<'de>`]deserialize().(&mut deserializer).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| deserializer.span_errorrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]span_error().(e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
110
111 deserializer.endrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]end().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| deserializer.span_errorrust-analyzer cargo ron 0.12.0 de/impl#[`Deserializer<'de>`]span_error().(e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
112
113 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]::from_borrowed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_borrowed_str().(ron))
114 }
115
116 /// Helper function to validate a RON string and turn it into a
117 /// [`RawValue`].
118 pub fn from_boxed_ronrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_ron().(ron: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>) -> SpannedResultrust-analyzer cargo ron 0.12.0 error/SpannedResult#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]>> {
119 match Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]::from_ronrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_ron().(&ron) {
120 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(ron)),
121 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err),
122 }
123 }
124
125 /// Helper function to deserialize the inner RON string into `T`.
126 pub fn into_rustrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]into_rust().<'de, T: Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de>>(&'de self) -> SpannedResultrust-analyzer cargo ron 0.12.0 error/SpannedResult#<T> {
127 Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().from_strrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str().(&self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.)
128 }
129
130 /// Helper function to serialize `value` into a RON string.
131 pub fn from_rustrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_rust().<T: Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#>(value: &T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]>, Errorrust-analyzer cargo ron 0.12.0 error/Error#> {
132 let ron = Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().to_stringrust-analyzer cargo ron 0.12.0 options/impl#[Options]to_string().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
133
134 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(ron.into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().()))
135 }
136 }
137
138 impl RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
139 #[must_use]
140 /// Trims any leadning and trailing whitespace off the raw RON string,
141 /// including whitespace characters and comments.
142 pub fn trimrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]trim().(&self) -> &Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue] {
143 Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]::from_borrowed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_borrowed_str().(&self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][`Index<I>`]index().RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::trim_rangerust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]trim_range().(&self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][`Index<I>`]index().)
144 }
145
146 #[must_use]
147 #[allow(unsafe_code)]
148 /// Trims any leadning and trailing whitespace off the boxed raw RON string,
149 /// including whitespace characters and comments.
150 pub fn trim_boxedrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]trim_boxed().(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]> {
151 let trim_range = RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::trim_rangerust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]trim_range().(&self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.);
152 let mut boxed_ron = RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::into_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]into_boxed_str().(self).into_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]into_string().();
153 // SAFETY: ron[trim_range] is a valid str, so draining everything
154 // before and after leaves a valid str
155 unsafe {
156 boxed_ron.as_mut_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_mut_vec().().drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(trim_range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#);
157 boxed_ron.as_mut_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_mut_vec().().drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#trim_range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.);
158 }
159 RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(boxed_ron.into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().())
160 }
161 }
162
163 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>> for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str> {
164 fn fromrust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<str>`][`From<Box<RawValue>>`]from().(raw_value: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>) -> Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<str>`][`From<Box<RawValue>>`] {
165 RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::into_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]into_boxed_str().(raw_value)
166 }
167 }
168
169 impl Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize# for RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
170 fn serializerust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue][Serialize]serialize().<S: serrust-analyzer cargo serde_core 1.0.228 ser/::Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#>(&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.228 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Error#> {
171 serializer.serialize_newtype_structrust-analyzer cargo serde_core 1.0.228 ser/Serializer#serialize_newtype_struct().(RAW_VALUE_TOKENrust-analyzer cargo ron 0.12.0 value/raw/RAW_VALUE_TOKEN., &self.ronrust-analyzer cargo ron 0.12.0 value/raw/RawValue#ron.)
172 }
173 }
174
175 impl<'de: 'a, 'a> Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de> for &'a RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue# {
176 fn deserializerust-analyzer cargo ron 0.12.0 value/raw/impl#[`&'a RawValue`][`Deserialize<'de>`]deserialize().<D: derust-analyzer cargo serde_core 1.0.228 de/::Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[`&'a RawValue`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> {
177 struct ReferenceVisitorrust-analyzer cargo ron 0.12.0 value/raw/ReferenceVisitor#;
178
179 impl<'de> derust-analyzer cargo serde_core 1.0.228 de/::Visitorrust-analyzer cargo serde_core 1.0.228 de/Visitor#<'de> for ReferenceVisitorrust-analyzer cargo ron 0.12.0 value/raw/ReferenceVisitor# {
180 type Valuerust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`Visitor<'de>`]Value# = &'de RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#;
181
182 fn expectingrust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`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# {
183 // This error message only shows up with foreign Deserializers
184 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "any valid borrowed RON-value-string")
185 }
186
187 fn visit_borrowed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`Visitor<'de>`]visit_borrowed_str().<E: derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#>(self, ron: &'de str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.228 de/Visitor#Value#, E> {
188 match Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().from_strrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str().::<derust-analyzer cargo serde_core 1.0.228 de/::IgnoredAnyrust-analyzer cargo serde_core 1.0.228 de/ignored_any/IgnoredAny#>(ron) {
189 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_borrowed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_borrowed_str().(ron)),
190 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#::customrust-analyzer cargo serde_core 1.0.228 de/Error#custom().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid RON value at {}", err))),
191 }
192 }
193
194 fn visit_newtype_structrust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`Visitor<'de>`]visit_newtype_struct().<D: derust-analyzer cargo serde_core 1.0.228 de/::Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>>(
195 self,
196 deserializer: D,
197 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[ReferenceVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.228 de/Visitor#Value#, D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> {
198 deserializer.deserialize_strrust-analyzer cargo serde_core 1.0.228 de/Deserializer#deserialize_str().(self)
199 }
200 }
201
202 deserializer.deserialize_newtype_structrust-analyzer cargo serde_core 1.0.228 de/Deserializer#deserialize_newtype_struct().(RAW_VALUE_TOKENrust-analyzer cargo ron 0.12.0 value/raw/RAW_VALUE_TOKEN., ReferenceVisitorrust-analyzer cargo ron 0.12.0 value/raw/ReferenceVisitor#)
203 }
204 }
205
206 impl<'de> Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de> for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#> {
207 fn deserializerust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<RawValue>`][`Deserialize<'de>`]deserialize().<D: derust-analyzer cargo serde_core 1.0.228 de/::Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[`Box<RawValue>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> {
208 struct BoxedVisitorrust-analyzer cargo ron 0.12.0 value/raw/BoxedVisitor#;
209
210 impl<'de> derust-analyzer cargo serde_core 1.0.228 de/::Visitorrust-analyzer cargo serde_core 1.0.228 de/Visitor#<'de> for BoxedVisitorrust-analyzer cargo ron 0.12.0 value/raw/BoxedVisitor# {
211 type Valuerust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]Value# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#>;
212
213 fn expectingrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`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# {
214 // This error message only shows up with foreign Deserializers
215 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "any valid RON-value-string")
216 }
217
218 fn visit_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]visit_str().<E: derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#>(self, ron: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.228 de/Visitor#Value#, E> {
219 match Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().from_strrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str().::<derust-analyzer cargo serde_core 1.0.228 de/::IgnoredAnyrust-analyzer cargo serde_core 1.0.228 de/ignored_any/IgnoredAny#>(ron) {
220 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(ron.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().().into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().())),
221 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#::customrust-analyzer cargo serde_core 1.0.228 de/Error#custom().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid RON value at {}", err))),
222 }
223 }
224
225 fn visit_stringrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]visit_string().<E: derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#>(self, ron: 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#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.228 de/Visitor#Value#, E> {
226 match Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().from_strrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str().::<derust-analyzer cargo serde_core 1.0.228 de/::IgnoredAnyrust-analyzer cargo serde_core 1.0.228 de/ignored_any/IgnoredAny#>(&ron) {
227 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RawValuerust-analyzer cargo ron 0.12.0 value/raw/RawValue#::from_boxed_strrust-analyzer cargo ron 0.12.0 value/raw/impl#[RawValue]from_boxed_str().(ron.into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().())),
228 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#::customrust-analyzer cargo serde_core 1.0.228 de/Error#custom().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid RON value at {}", err))),
229 }
230 }
231
232 fn visit_newtype_structrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]visit_newtype_struct().<D: derust-analyzer cargo serde_core 1.0.228 de/::Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>>(
233 self,
234 deserializer: D,
235 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ron 0.12.0 value/raw/impl#[BoxedVisitor][`Visitor<'de>`]::Valuerust-analyzer cargo serde_core 1.0.228 de/Visitor#Value#, D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> {
236 deserializer.deserialize_stringrust-analyzer cargo serde_core 1.0.228 de/Deserializer#deserialize_string().(self)
237 }
238 }
239
240 deserializer.deserialize_newtype_structrust-analyzer cargo serde_core 1.0.228 de/Deserializer#deserialize_newtype_struct().(RAW_VALUE_TOKENrust-analyzer cargo ron 0.12.0 value/raw/RAW_VALUE_TOKEN., BoxedVisitorrust-analyzer cargo ron 0.12.0 value/raw/BoxedVisitor#)
241 }
242 }