Debian Codegraph @

src/mime.rs

raw symbols SCIP
1 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#, 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#, 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#};
2 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
3 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#;
4
5 /// <https://mimesniff.spec.whatwg.org/#mime-type-representation>
6 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, 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:)]
7 pub struct Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
8 pub type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
9 pub subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
10 /// (name, value)
11 pub parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>,
12 }
13
14 impl Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
15 /// Construct a new [`Mime`] with the given `type_` and `subtype` and an
16 /// empty parameter list.
17 pub fn newrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]new().(type_: &str, subtype: &str) -> Selfrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime] {
18 Selfrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime] {
19 type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_.: type_.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
20 subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype.: subtype.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
21 parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
22 }
23 }
24
25 /// Return true if this [`Mime`] matches a given type and subtype, regardless
26 /// of what parameters it has.
27 pub fn matchesrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]matches().(&self, type_: &str, subtype: &str) -> bool {
28 self.type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().type_ && self.subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().subtype
29 }
30
31 pub fn get_parameterrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]get_parameter().<P>(&self, name: &P) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>
32 where
33 P: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<str>,
34 {
35 self.parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters.
36 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
37 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|&(n, _)| name 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 alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().n)
38 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_, v)| &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v)
39 }
40 }
41
42 #[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:)]
43 pub struct MimeParsingErrorrust-analyzer cargo data-url 0.3.2 mime/MimeParsingError#(());
44
45 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 MimeParsingErrorrust-analyzer cargo data-url 0.3.2 mime/MimeParsingError# {
46 fn fmtrust-analyzer cargo data-url 0.3.2 mime/impl#[MimeParsingError][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# {
47 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid mime type")
48 }
49 }
50
51 #[cfg(feature = "std")]
52 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for MimeParsingErrorrust-analyzer cargo data-url 0.3.2 mime/MimeParsingError# {}
53
54 /// <https://mimesniff.spec.whatwg.org/#parsing-a-mime-type>
55 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
56 type Errrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][FromStr]Err# = MimeParsingErrorrust-analyzer cargo data-url 0.3.2 mime/MimeParsingError#;
57
58 fn from_strrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][FromStr], Selfrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
59 parserust-analyzer cargo data-url 0.3.2 mime/parse().(s).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(MimeParsingErrorrust-analyzer cargo data-url 0.3.2 mime/MimeParsingError#(()))
60 }
61 }
62
63 fn parserust-analyzer cargo data-url 0.3.2 mime/parse().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Mimerust-analyzer cargo data-url 0.3.2 mime/Mime#> {
64 let trimmed = s.trim_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_matches().(http_whitespacerust-analyzer cargo data-url 0.3.2 mime/http_whitespace().);
65
66 let (type_, rest) = split2rust-analyzer cargo data-url 0.3.2 mime/split2().(trimmed, '/');
67 requirerust-analyzer cargo data-url 0.3.2 require!!(only_http_token_code_pointsrust-analyzer cargo data-url 0.3.2 mime/only_http_token_code_points().(type_) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().type_.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().());
68
69 let (subtype, rest) = split2rust-analyzer cargo data-url 0.3.2 mime/split2().(rest?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()., ';');
70 let subtype = subtype.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(http_whitespacerust-analyzer cargo data-url 0.3.2 mime/http_whitespace().);
71 requirerust-analyzer cargo data-url 0.3.2 require!!(only_http_token_code_pointsrust-analyzer cargo data-url 0.3.2 mime/only_http_token_code_points().(subtype) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().subtype.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().());
72
73 let mut parameters = 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().();
74 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rest) = rest {
75 parse_parametersrust-analyzer cargo data-url 0.3.2 mime/parse_parameters().(rest, &mut parameters)
76 }
77
78 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
79 type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_.: type_.to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().(),
80 subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype.: subtype.to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().(),
81 parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters.,
82 })
83 }
84
85 fn split2rust-analyzer cargo data-url 0.3.2 mime/split2().(s: &str, separator: char) -> (&str, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) {
86 let mut iter = s.splitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]splitn().(2, separator);
87 let first = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
88 (first, iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().())
89 }
90
91 fn parse_parametersrust-analyzer cargo data-url 0.3.2 mime/parse_parameters().(s: &str, parameters: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>) {
92 let mut semicolon_separated = s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(';');
93
94 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(piece) = semicolon_separated.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
95 let piece = piece.trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().(http_whitespacerust-analyzer cargo data-url 0.3.2 mime/http_whitespace().);
96 let (name, value) = split2rust-analyzer cargo data-url 0.3.2 mime/split2().(piece, '=');
97 // We can not early return on an invalid name here, because the value
98 // parsing later may consume more semicolon seperated pieces.
99 let name_valid =
100 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().name.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() && only_http_token_code_pointsrust-analyzer cargo data-url 0.3.2 mime/only_http_token_code_points().(name) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().containsrust-analyzer cargo data-url 0.3.2 mime/contains().(parameters, name);
101 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = value {
102 let value = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stripped) = value.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('"') {
103 let max_len = stripped.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); // without end quote
104 let mut unescaped_value = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(max_len);
105 let mut chars = stripped.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().();
106 'until_closing_quote: loop {
107 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() {
108 match c {
109 '"' => break 'until_closing_quote,
110 '\\' => unescaped_value.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
111 semicolon_separated
112 .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().()
113 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|piece| {
114 // A semicolon inside a quoted value is not a separator
115 // for the next parameter, but part of the value.
116 chars = piece.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().();
117 ';'
118 })
119 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().('\\')
120 })),
121 _ => unescaped_value.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c),
122 }
123 }
124 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(piece) = semicolon_separated.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
125 // A semicolon inside a quoted value is not a separator
126 // for the next parameter, but part of the value.
127 unescaped_value.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(';');
128 chars = piece.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().()
129 } else {
130 break;
131 }
132 }
133 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().name_valid || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_valuerust-analyzer cargo data-url 0.3.2 mime/valid_value().(value) {
134 continue;
135 }
136 unescaped_value
137 } else {
138 let value = value.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(http_whitespacerust-analyzer cargo data-url 0.3.2 mime/http_whitespace().);
139 if value.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
140 continue;
141 }
142 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().name_valid || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_valuerust-analyzer cargo data-url 0.3.2 mime/valid_value().(value) {
143 continue;
144 }
145 value.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
146 };
147 parameters.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((name.to_ascii_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_ascii_lowercase().(), value))
148 }
149 }
150 }
151
152 fn containsrust-analyzer cargo data-url 0.3.2 mime/contains().(parameters: &[(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)], name: &str) -> bool {
153 parameters.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().(|(n, _)| n 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().name)
154 }
155
156 fn valid_valuerust-analyzer cargo data-url 0.3.2 mime/valid_value().(s: &str) -> bool {
157 s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| {
158 // <https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point>
159 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, '\t' | ' '..='~' | '\u{80}'..='\u{FF}')
160 })
161 }
162
163 /// <https://mimesniff.spec.whatwg.org/#serializing-a-mime-type>
164 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 Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
165 fn fmtrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][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# {
166 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
167 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("/")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
168 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
169 for (name, value) in &self.parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters. {
170 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(";")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
171 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
172 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("=")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
173 if only_http_token_code_pointsrust-analyzer cargo data-url 0.3.2 mime/only_http_token_code_points().(value) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
174 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
175 } else {
176 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
177 for c in value.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
178 if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'"' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\\' {
179 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\\")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
180 }
181 f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(c)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
182 }
183 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
184 }
185 }
186 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
187 }
188 }
189
190 fn http_whitespacerust-analyzer cargo data-url 0.3.2 mime/http_whitespace().(c: char) -> bool {
191 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, ' ' | '\t' | '\n' | '\r')
192 }
193
194 fn only_http_token_code_pointsrust-analyzer cargo data-url 0.3.2 mime/only_http_token_code_points().(s: &str) -> bool {
195 s.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Bytes<'_>`][Iterator]all().(|byte| IS_HTTP_TOKENrust-analyzer cargo data-url 0.3.2 mime/IS_HTTP_TOKEN.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().byte as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)
196 }
197
198 macro_rules! byte_maprust-analyzer cargo data-url 0.3.2 mime/byte_map! {
199 ($($flag:expr,)*) => ([
200 $($flag != 0,)*
201 ])
202 }
203
204 // Copied from https://github.com/hyperium/mime/blob/v0.3.5/src/parse.rs#L293
205 #[rustfmt::skip]
206 static IS_HTTP_TOKENrust-analyzer cargo data-url 0.3.2 mime/IS_HTTP_TOKEN.: [bool; 256] = byte_maprust-analyzer cargo data-url 0.3.2 mime/byte_map!![
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
210 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
211 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
212 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
213 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
214 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
223 ];
224
225 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
226 fn test_basic_mimerust-analyzer cargo data-url 0.3.2 mime/test_basic_mime().() {
227 let mime = Mimerust-analyzer cargo data-url 0.3.2 mime/Mime#::newrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]new().("text", "plain");
228 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mime.matchesrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]matches().("text", "plain"));
229
230 let cloned = mime.clonerust-analyzer cargo data-url 0.3.2 mime/impl#[Mime][Clone]clone().();
231 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cloned.matchesrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]matches().("text", "plain"));
232
233 let mime = Mimerust-analyzer cargo data-url 0.3.2 mime/Mime# {
234 type_rust-analyzer cargo data-url 0.3.2 mime/Mime#type_.: "text".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
235 subtyperust-analyzer cargo data-url 0.3.2 mime/Mime#subtype.: "html".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
236 parametersrust-analyzer cargo data-url 0.3.2 mime/Mime#parameters.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![("one".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "two".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())],
237 };
238 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mime.matchesrust-analyzer cargo data-url 0.3.2 mime/impl#[Mime]matches().("text", "html"));
239 }