Debian Codegraph @

src/media_type.rs

raw symbols SCIP
1 use superrust-analyzer cargo mediatype 0.23.0 crate/::{errorrust-analyzer cargo mediatype 0.23.0 error/::*, media_type_bufrust-analyzer cargo mediatype 0.23.0 media_type_buf/::*, namerust-analyzer cargo mediatype 0.23.0 name/::*, paramsrust-analyzer cargo mediatype 0.23.0 params/::*, parserust-analyzer cargo mediatype 0.23.0 parse/::*, valuerust-analyzer cargo mediatype 0.23.0 value/::*};
2 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/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#};
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{
4 fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/,
5 hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#},
6 };
7
8 /// A borrowed media type.
9 ///
10 /// ```
11 /// use mediatype::{names::*, MediaType, Value, WriteParams};
12 ///
13 /// let mut multipart = MediaType::new(MULTIPART, FORM_DATA);
14 ///
15 /// let boundary = Value::new("dyEV84n7XNJ").unwrap();
16 /// multipart.set_param(BOUNDARY, boundary);
17 /// assert_eq!(
18 /// multipart.to_string(),
19 /// "multipart/form-data; boundary=dyEV84n7XNJ"
20 /// );
21 ///
22 /// multipart.subty = RELATED;
23 /// assert_eq!(
24 /// multipart.to_string(),
25 /// "multipart/related; boundary=dyEV84n7XNJ"
26 /// );
27 ///
28 /// const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[]);
29 /// let svg = MediaType::parse("IMAGE/SVG+XML").unwrap();
30 /// assert_eq!(svg, IMAGE_SVG);
31 /// ```
32 #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
33 pub struct MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'a> {
34 /// Top-level type.
35 pub tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
36
37 /// Subtype.
38 pub subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
39
40 /// Optional suffix.
41 pub suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>>,
42
43 /// Parameters.
44 pub paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [(Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>, Valuerust-analyzer cargo mediatype 0.23.0 value/Value#<'a>)]>,
45 }
46
47 impl<'a> MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'a> {
48 /// Constructs a `MediaType` from a top-level type and a subtype.
49 /// ```
50 /// # use mediatype::{names::*, MediaType};
51 /// const IMAGE_PNG: MediaType = MediaType::new(IMAGE, PNG);
52 /// assert_eq!(IMAGE_PNG, MediaType::parse("image/png").unwrap());
53 /// ```
54 #[must_use]
55 pub const fn newrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]new().(ty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>, subty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>) -> Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
56 Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
57 tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.,
58 subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.,
59 suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
60 paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[]),
61 }
62 }
63
64 /// Constructs a `MediaType` with an optional suffix and parameters.
65 ///
66 /// ```
67 /// # use mediatype::{names::*, values::*, MediaType};
68 /// const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[(CHARSET, UTF_8)]);
69 /// assert_eq!(
70 /// IMAGE_SVG,
71 /// MediaType::parse("image/svg+xml; charset=UTF-8").unwrap()
72 /// );
73 /// ```
74 #[must_use]
75 pub const fn from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(
76 ty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
77 subty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
78 suffix: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>>,
79 params: &'a [(Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>, Valuerust-analyzer cargo mediatype 0.23.0 value/Value#<'a>)],
80 ) -> Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
81 Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
82 tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.,
83 subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.,
84 suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.,
85 paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(params),
86 }
87 }
88
89 pub(craterust-analyzer cargo mediatype 0.23.0 crate/) const fn from_parts_uncheckedrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts_unchecked().(
90 ty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
91 subty: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>,
92 suffix: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>>,
93 params: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [(Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'a>, Valuerust-analyzer cargo mediatype 0.23.0 value/Value#<'a>)]>,
94 ) -> Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
95 Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
96 tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.,
97 subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.,
98 suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.,
99 paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.,
100 }
101 }
102
103 /// Constructs a `MediaType` from `str` without copying the string.
104 ///
105 /// # Errors
106 ///
107 /// Returns an error if the string fails to be parsed.
108 pub fn parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().<'s: 'a>(s: &'s str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`], MediaTypeErrorrust-analyzer cargo mediatype 0.23.0 error/MediaTypeError#> {
109 let (indices, _) = Indicesrust-analyzer cargo mediatype 0.23.0 parse/Indices#::parserust-analyzer cargo mediatype 0.23.0 parse/impl#[Indices]parse().(s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
110 let params = indices
111 .paramsrust-analyzer cargo mediatype 0.23.0 parse/impl#[Indices]params().()
112 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
113 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|param| {
114 (
115 Namerust-analyzer cargo mediatype 0.23.0 name/Name#::new_uncheckedrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new_unchecked().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().param[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#param[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
116 Valuerust-analyzer cargo mediatype 0.23.0 value/Value#::new_uncheckedrust-analyzer cargo mediatype 0.23.0 value/impl#[`Value<'a>`]new_unchecked().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().param[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#param[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
117 )
118 })
119 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
120 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`] {
121 tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.: Namerust-analyzer cargo mediatype 0.23.0 name/Name#::new_uncheckedrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new_unchecked().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().indices.tyrust-analyzer cargo mediatype 0.23.0 parse/impl#[Indices]ty().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
122 subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.: Namerust-analyzer cargo mediatype 0.23.0 name/Name#::new_uncheckedrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new_unchecked().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().indices.subtyrust-analyzer cargo mediatype 0.23.0 parse/impl#[Indices]subty().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
123 suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.: indices.suffixrust-analyzer cargo mediatype 0.23.0 parse/impl#[Indices]suffix().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|range| Namerust-analyzer cargo mediatype 0.23.0 name/Name#::new_uncheckedrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new_unchecked().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().range]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)),
124 paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(params),
125 })
126 }
127
128 /// Returns a [`MediaType`] without parameters.
129 ///
130 /// ```
131 /// # use mediatype::{names::*, values::*, MediaType};
132 /// const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[(CHARSET, UTF_8)]);
133 /// assert_eq!(
134 /// IMAGE_SVG.essence(),
135 /// MediaType::parse("image/svg+xml").unwrap()
136 /// );
137 /// ```
138 ///
139 /// [`MadiaType`]: ./struct.MediaType.html
140 #[must_use]
141 pub const fn essencerust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]essence().(&self) -> MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
142 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(self.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty., self.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty., self.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix., &[])
143 }
144 }
145
146 impl ReadParamsrust-analyzer cargo mediatype 0.23.0 params/ReadParams# for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
147 fn paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]params().(&self) -> Paramsrust-analyzer cargo mediatype 0.23.0 params/Params#<'_> {
148 Paramsrust-analyzer cargo mediatype 0.23.0 params/Params#::from_slicerust-analyzer cargo mediatype 0.23.0 params/impl#[`Params<'a>`]from_slice().(&self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.)
149 }
150
151 fn get_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]get_param().(&self, name: Namerust-analyzer cargo mediatype 0.23.0 name/Name#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Valuerust-analyzer cargo mediatype 0.23.0 value/Value#<'_>> {
152 self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params.
153 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
154 .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()
155 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/rev/impl#[`Rev<I>`][Iterator]find().(|&&param| name rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().param.0)
156 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|&(_, value)| value)
157 }
158 }
159
160 impl<'a> WriteParamsrust-analyzer cargo mediatype 0.23.0 params/WriteParams#<'a> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'a> {
161 fn set_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]set_param().<'n: 'a, 'v: 'a>(&mut self, name: Namerust-analyzer cargo mediatype 0.23.0 name/Name#<'n>, value: Valuerust-analyzer cargo mediatype 0.23.0 value/Value#<'v>) {
162 self.remove_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]remove_params().(name);
163 let params = self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params..to_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]to_mut().();
164 params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((name, value));
165 }
166
167 fn remove_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]remove_params().(&mut self, name: Namerust-analyzer cargo mediatype 0.23.0 name/Name#) {
168 let key_exists = self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|&param| name rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().param.0);
169 if key_exists {
170 self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params..to_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]to_mut().().retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]retain().(|&param| name rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().param.0);
171 }
172 }
173
174 fn clear_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]clear_params().(&mut self) {
175 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params..is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
176 self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params..to_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]to_mut().().clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
177 }
178 }
179 }
180
181 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 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
182 fn fmtrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][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# {
183 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}/{}", self.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty., self.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
184 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(suffix) = self.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix. {
185 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "+{}", suffix)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
186 }
187 for (name, value) in &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#params. {
188 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "; {}={}", name, value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
189 }
190 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
191 }
192 }
193
194 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'a> {
195 fn fromrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`From<&'a MediaTypeBuf>`]from().(t: &'a MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#) -> Selfrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`From<&'a MediaTypeBuf>`] {
196 t.to_refrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]to_ref().()
197 }
198 }
199
200 impl<'b> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'b>> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
201 fn eqrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][`PartialEq<MediaType<'b>>`]eq().(&self, other: &MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'b>) -> bool {
202 self.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty. rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().other.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty.
203 && self.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty. rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().other.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty.
204 && self.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().other.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix.
205 && self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]params().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<_, _>>()
206 ==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`PartialEq<Self>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`PartialEq<Self>`]eq().other.paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]params().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<_, _>>()
207 }
208 }
209
210 impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {}
211
212 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
213 fn eqrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][`PartialEq<MediaTypeBuf>`]eq().(&self, other: &MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#) -> bool {
214 self.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty. rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().other.tyrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]ty().()
215 && self.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty. rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().==rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq(). rust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][`PartialEq<Self>`]eq().other.subtyrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]subty().()
216 && self.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().other.suffixrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf]suffix().()
217 && self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]params().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<_, _>>()
218 ==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`PartialEq<Self>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][`PartialEq<Self>`]eq().other.paramsrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf][ReadParams]params().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<_, _>>()
219 }
220 }
221
222 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#> for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
223 fn eqrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][`PartialEq<&MediaTypeBuf>`]eq().(&self, other: &&MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#) -> bool {
224 self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other
225 }
226 }
227
228 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#<'_> {
229 fn hashrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
230 self.tyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#ty..hashrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Hash]hash().(state);
231 self.subtyrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#subty..hashrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'_>`][Hash]hash().(state);
232 self.suffixrust-analyzer cargo mediatype 0.23.0 media_type/MediaType#suffix..hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Hash]hash().(state);
233 self.paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]params().()
234 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<_, _>>()
235 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][IntoIterator]into_iter().()
236 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()
237 .hashrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Hash]hash().(state);
238 }
239 }
240
241 #[cfg(test)]
242 mod testsrust-analyzer cargo mediatype 0.23.0 media_type/tests/ {
243 use superrust-analyzer cargo mediatype 0.23.0 media_type/::*;
244 use craterust-analyzer cargo mediatype 0.23.0 crate/::{namesrust-analyzer cargo mediatype 0.23.0 consts/names/::*, valuesrust-analyzer cargo mediatype 0.23.0 consts/values/::*};
245 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#;
246 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
247 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/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::DefaultHasherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/DefaultHasher#;
248
249 fn calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().<T: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#>(t: &T) -> u64 {
250 let mut s = DefaultHasherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/DefaultHasher#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[DefaultHasher]new().();
251 t.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#hash().(&mut s);
252 s.finishrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[DefaultHasher][Hasher]finish().()
253 }
254
255 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
256 fn to_stringrust-analyzer cargo mediatype 0.23.0 media_type/tests/to_string().() {
257 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::newrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]new().(_STARrust-analyzer cargo mediatype 0.23.0 consts/names/_STAR., _STARrust-analyzer cargo mediatype 0.23.0 consts/names/_STAR.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "*/*");
258 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::newrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]new().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "text/plain");
259 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
260 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(IMAGErust-analyzer cargo mediatype 0.23.0 consts/names/IMAGE., SVGrust-analyzer cargo mediatype 0.23.0 consts/names/SVG., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(XMLrust-analyzer cargo mediatype 0.23.0 consts/names/XML.), &[]).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
261 "image/svg+xml"
262 );
263 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
264 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
265 "text/plain; charset=UTF-8"
266 );
267 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
268 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(IMAGErust-analyzer cargo mediatype 0.23.0 consts/names/IMAGE., SVGrust-analyzer cargo mediatype 0.23.0 consts/names/SVG., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(XMLrust-analyzer cargo mediatype 0.23.0 consts/names/XML.), &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
269 "image/svg+xml; charset=UTF-8"
270 );
271 }
272
273 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
274 fn get_paramrust-analyzer cargo mediatype 0.23.0 media_type/tests/get_param().() {
275 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::newrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]new().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN.).get_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]get_param().(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET.), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
276 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
277 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]).get_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]get_param().(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET.),
278 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)
279 );
280 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
281 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; charset=UTF-8; HELLO=WORLD; HELLO=world")
282 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
283 .get_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'_>`][ReadParams]get_param().(Namerust-analyzer cargo mediatype 0.23.0 name/Name#::newrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new().("hello").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()),
284 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo mediatype 0.23.0 value/Value#::newrust-analyzer cargo mediatype 0.23.0 value/impl#[`Value<'a>`]new().("world").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
285 );
286 }
287
288 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
289 fn set_paramrust-analyzer cargo mediatype 0.23.0 media_type/tests/set_param().() {
290 let mut media_type = MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]);
291 let lower_utf8 = Valuerust-analyzer cargo mediatype 0.23.0 value/Value#::newrust-analyzer cargo mediatype 0.23.0 value/impl#[`Value<'a>`]new().("utf-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
292 media_type.set_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]set_param().(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., lower_utf8);
293 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "text/plain; charset=utf-8");
294
295 let alice = Namerust-analyzer cargo mediatype 0.23.0 name/Name#::newrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new().("ALICE").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
296 let bob = Valuerust-analyzer cargo mediatype 0.23.0 value/Value#::newrust-analyzer cargo mediatype 0.23.0 value/impl#[`Value<'a>`]new().("bob").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
297 media_type.set_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]set_param().(alice, bob);
298 media_type.set_paramrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]set_param().(alice, bob);
299
300 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
301 media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
302 "text/plain; charset=utf-8; ALICE=bob"
303 );
304 }
305
306 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
307 fn remove_paramsrust-analyzer cargo mediatype 0.23.0 media_type/tests/remove_params().() {
308 let mut media_type = MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]);
309 media_type.remove_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]remove_params().(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET.);
310 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "text/plain");
311
312 let mut media_type =
313 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; hello=WORLD; charset=UTF-8; HELLO=WORLD").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
314 media_type.remove_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]remove_params().(Namerust-analyzer cargo mediatype 0.23.0 name/Name#::newrust-analyzer cargo mediatype 0.23.0 name/impl#[`Name<'a>`]new().("hello").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
315 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "image/svg+xml; charset=UTF-8");
316 }
317
318 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
319 fn clear_paramsrust-analyzer cargo mediatype 0.23.0 media_type/tests/clear_params().() {
320 let mut media_type = MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; charset=UTF-8; HELLO=WORLD").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
321 media_type.clear_paramsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`][`WriteParams<'a>`]clear_params().();
322 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(media_type.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "image/svg+xml");
323 }
324
325 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
326 fn cmprust-analyzer cargo mediatype 0.23.0 media_type/tests/cmp().() {
327 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
328 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("text/plain").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
329 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("TEXT/PLAIN").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
330 );
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
332 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; charset=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
333 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("IMAGE/SVG+XML; CHARSET=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
334 );
335 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
336 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; hello=WORLD; charset=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
337 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("IMAGE/SVG+XML; HELLO=WORLD; CHARSET=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
338 );
339 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
340 MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(
341 IMAGErust-analyzer cargo mediatype 0.23.0 consts/names/IMAGE.,
342 SVGrust-analyzer cargo mediatype 0.23.0 consts/names/SVG.,
343 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(XMLrust-analyzer cargo mediatype 0.23.0 consts/names/XML.),
344 &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., US_ASCIIrust-analyzer cargo mediatype 0.23.0 consts/values/US_ASCII.), (CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]
345 ),
346 MediaTypeBufrust-analyzer cargo mediatype 0.23.0 media_type_buf/MediaTypeBuf#::from_strrust-analyzer cargo mediatype 0.23.0 media_type_buf/impl#[MediaTypeBuf][FromStr]from_str().("image/svg+xml; charset=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
347 );
348
349 const TEXT_PLAINrust-analyzer cargo mediatype 0.23.0 media_type/tests/TEXT_PLAIN.: MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType# = MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(TEXTrust-analyzer cargo mediatype 0.23.0 consts/names/TEXT., PLAINrust-analyzer cargo mediatype 0.23.0 consts/names/PLAIN., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[]);
350 let text_plain = MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("text/plain").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
351 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(text_plain.essencerust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]essence().(), TEXT_PLAINrust-analyzer cargo mediatype 0.23.0 media_type/tests/TEXT_PLAIN.);
352 }
353
354 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
355 fn hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/hash().() {
356 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
357 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("text/plain").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
358 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("TEXT/PLAIN").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
359 );
360 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
361 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; charset=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
362 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("IMAGE/SVG+XML; CHARSET=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
363 );
364 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
365 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("image/svg+xml; hello=WORLD; charset=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()),
366 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::parserust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]parse().("IMAGE/SVG+XML; HELLO=WORLD; CHARSET=UTF-8").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
367 );
368 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
369 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(
370 IMAGErust-analyzer cargo mediatype 0.23.0 consts/names/IMAGE.,
371 SVGrust-analyzer cargo mediatype 0.23.0 consts/names/SVG.,
372 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(XMLrust-analyzer cargo mediatype 0.23.0 consts/names/XML.),
373 &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]
374 )),
375 calculate_hashrust-analyzer cargo mediatype 0.23.0 media_type/tests/calculate_hash().(&MediaTyperust-analyzer cargo mediatype 0.23.0 media_type/MediaType#::from_partsrust-analyzer cargo mediatype 0.23.0 media_type/impl#[`MediaType<'a>`]from_parts().(
376 IMAGErust-analyzer cargo mediatype 0.23.0 consts/names/IMAGE.,
377 SVGrust-analyzer cargo mediatype 0.23.0 consts/names/SVG.,
378 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(XMLrust-analyzer cargo mediatype 0.23.0 consts/names/XML.),
379 &[(CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., US_ASCIIrust-analyzer cargo mediatype 0.23.0 consts/values/US_ASCII.), (CHARSETrust-analyzer cargo mediatype 0.23.0 consts/names/CHARSET., UTF_8rust-analyzer cargo mediatype 0.23.0 consts/values/UTF_8.)]
380 )),
381 );
382 }
383 }