Skip to content

Commit 2c4aaf4

Browse files
GuillaumeGomezUrgau
authored andcommitted
Fix fmt
1 parent 7f9b23e commit 2c4aaf4

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

src/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ impl From<char> for MixedUnit {
134134

135135
impl From<u8> for MixedUnit {
136136
fn from(n: u8) -> Self {
137-
if n.is_ascii() { MixedUnit::Char(n as char) } else { MixedUnit::HighByte(n) }
137+
if n.is_ascii() {
138+
MixedUnit::Char(n as char)
139+
} else {
140+
MixedUnit::HighByte(n)
141+
}
138142
}
139143
}
140144

@@ -280,7 +284,9 @@ fn scan_unicode(chars: &mut Chars<'_>, allow_unicode_escapes: bool) -> Result<ch
280284
let mut value: u32 = match chars.next().ok_or(EscapeError::UnclosedUnicodeEscape)? {
281285
'_' => return Err(EscapeError::LeadingUnderscoreUnicodeEscape),
282286
'}' => return Err(EscapeError::EmptyUnicodeEscape),
283-
c => c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?,
287+
c => c
288+
.to_digit(16)
289+
.ok_or(EscapeError::InvalidCharInUnicodeEscape)?,
284290
};
285291

286292
// First character is valid, now parse the rest of the number
@@ -309,7 +315,9 @@ fn scan_unicode(chars: &mut Chars<'_>, allow_unicode_escapes: bool) -> Result<ch
309315
});
310316
}
311317
Some(c) => {
312-
let digit: u32 = c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
318+
let digit: u32 = c
319+
.to_digit(16)
320+
.ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
313321
n_digits += 1;
314322
if n_digits > 6 {
315323
// Stop updating value since we're sure that it's incorrect already.
@@ -323,7 +331,11 @@ fn scan_unicode(chars: &mut Chars<'_>, allow_unicode_escapes: bool) -> Result<ch
323331

324332
#[inline]
325333
fn ascii_check(c: char, allow_unicode_chars: bool) -> Result<char, EscapeError> {
326-
if allow_unicode_chars || c.is_ascii() { Ok(c) } else { Err(EscapeError::NonAsciiCharInByte) }
334+
if allow_unicode_chars || c.is_ascii() {
335+
Ok(c)
336+
} else {
337+
Err(EscapeError::NonAsciiCharInByte)
338+
}
327339
}
328340

329341
fn unescape_char_or_byte(chars: &mut Chars<'_>, mode: Mode) -> Result<char, EscapeError> {

src/tests.rs

+38-8
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ fn test_unescape_char_good() {
100100
fn test_unescape_str_warn() {
101101
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
102102
let mut unescaped = Vec::with_capacity(literal.len());
103-
unescape_unicode(literal, Mode::Str, &mut |range, res| unescaped.push((range, res)));
103+
unescape_unicode(literal, Mode::Str, &mut |range, res| {
104+
unescaped.push((range, res))
105+
});
104106
assert_eq!(unescaped, expected);
105107
}
106108

@@ -117,7 +119,13 @@ fn test_unescape_str_warn() {
117119
(6..7, Ok('x')),
118120
],
119121
);
120-
check("\\\n \n x", &[(0..7, Err(EscapeError::MultipleSkippedLinesWarning)), (7..8, Ok('x'))]);
122+
check(
123+
"\\\n \n x",
124+
&[
125+
(0..7, Err(EscapeError::MultipleSkippedLinesWarning)),
126+
(7..8, Ok('x')),
127+
],
128+
);
121129
}
122130

123131
#[test]
@@ -264,23 +272,45 @@ fn test_unescape_byte_str_good() {
264272
fn test_unescape_raw_str() {
265273
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
266274
let mut unescaped = Vec::with_capacity(literal.len());
267-
unescape_unicode(literal, Mode::RawStr, &mut |range, res| unescaped.push((range, res)));
275+
unescape_unicode(literal, Mode::RawStr, &mut |range, res| {
276+
unescaped.push((range, res))
277+
});
268278
assert_eq!(unescaped, expected);
269279
}
270280

271-
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
272-
check("\rx", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString)), (1..2, Ok('x'))]);
281+
check(
282+
"\r",
283+
&[(0..1, Err(EscapeError::BareCarriageReturnInRawString))],
284+
);
285+
check(
286+
"\rx",
287+
&[
288+
(0..1, Err(EscapeError::BareCarriageReturnInRawString)),
289+
(1..2, Ok('x')),
290+
],
291+
);
273292
}
274293

275294
#[test]
276295
fn test_unescape_raw_byte_str() {
277296
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
278297
let mut unescaped = Vec::with_capacity(literal.len());
279-
unescape_unicode(literal, Mode::RawByteStr, &mut |range, res| unescaped.push((range, res)));
298+
unescape_unicode(literal, Mode::RawByteStr, &mut |range, res| {
299+
unescaped.push((range, res))
300+
});
280301
assert_eq!(unescaped, expected);
281302
}
282303

283-
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
304+
check(
305+
"\r",
306+
&[(0..1, Err(EscapeError::BareCarriageReturnInRawString))],
307+
);
284308
check("🦀", &[(0..4, Err(EscapeError::NonAsciiCharInByte))]);
285-
check("🦀a", &[(0..4, Err(EscapeError::NonAsciiCharInByte)), (4..5, Ok('a'))]);
309+
check(
310+
"🦀a",
311+
&[
312+
(0..4, Err(EscapeError::NonAsciiCharInByte)),
313+
(4..5, Ok('a')),
314+
],
315+
);
286316
}

0 commit comments

Comments
 (0)