From ffacb5caaf4218d3999f2cac9203c77365f90d90 Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:47:52 -0500 Subject: [PATCH 1/9] cargo +nightly fix --- examples/recode.rs | 8 +-- src/codec/ascii.rs | 22 ++++---- src/codec/error.rs | 20 +++---- src/codec/japanese.rs | 110 +++++++++++++++++++-------------------- src/codec/korean.rs | 26 ++++----- src/codec/simpchinese.rs | 72 ++++++++++++------------- src/codec/singlebyte.rs | 20 +++---- src/codec/tradchinese.rs | 26 ++++----- src/codec/utf_16.rs | 70 ++++++++++++------------- src/codec/utf_8.rs | 22 ++++---- src/codec/whatwg.rs | 4 +- src/label.rs | 2 +- src/testutils.rs | 4 +- src/types.rs | 12 ++--- src/util.rs | 8 +-- 15 files changed, 213 insertions(+), 213 deletions(-) diff --git a/examples/recode.rs b/examples/recode.rs index cb6cbd2f..dabba0d6 100644 --- a/examples/recode.rs +++ b/examples/recode.rs @@ -64,16 +64,16 @@ fn main() { }; let mut input = match matches.free.first().map(|s| &s[..]) { - Some("-") | None => Box::new(io::stdin()) as Box, + Some("-") | None => Box::new(io::stdin()) as Box, Some(f) => match File::open(&Path::new(f)) { - Ok(f) => Box::new(f) as Box, + Ok(f) => Box::new(f) as Box, Err(e) => panic!("cannot open the input {}: {}", f, e), }, }; let mut output = match matches.opt_str("o").as_ref().map(|s| &s[..]) { - Some("-") | None => Box::new(io::stdout()) as Box, + Some("-") | None => Box::new(io::stdout()) as Box, Some(f) => match File::create(&Path::new(f)) { - Ok(f) => Box::new(f) as Box, + Ok(f) => Box::new(f) as Box, Err(e) => panic!("cannot open the output {}: {}", f, e), }, }; diff --git a/src/codec/ascii.rs b/src/codec/ascii.rs index d7f3e582..0d0465f2 100644 --- a/src/codec/ascii.rs +++ b/src/codec/ascii.rs @@ -19,8 +19,8 @@ pub struct ASCIIEncoding; impl Encoding for ASCIIEncoding { fn name(&self) -> &'static str { "ascii" } - fn raw_encoder(&self) -> Box { ASCIIEncoder::new() } - fn raw_decoder(&self) -> Box { ASCIIDecoder::new() } + fn raw_encoder(&self) -> Box { ASCIIEncoder::new() } + fn raw_decoder(&self) -> Box { ASCIIDecoder::new() } } /// An encoder for ASCII. @@ -28,14 +28,14 @@ impl Encoding for ASCIIEncoding { pub struct ASCIIEncoder; impl ASCIIEncoder { - pub fn new() -> Box { Box::new(ASCIIEncoder) } + pub fn new() -> Box { Box::new(ASCIIEncoder) } } impl RawEncoder for ASCIIEncoder { - fn from_self(&self) -> Box { ASCIIEncoder::new() } + fn from_self(&self) -> Box { ASCIIEncoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); match input.as_bytes().iter().position(|&ch| ch >= 0x80) { @@ -53,7 +53,7 @@ impl RawEncoder for ASCIIEncoder { } } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -63,17 +63,17 @@ impl RawEncoder for ASCIIEncoder { pub struct ASCIIDecoder; impl ASCIIDecoder { - pub fn new() -> Box { Box::new(ASCIIDecoder) } + pub fn new() -> Box { Box::new(ASCIIDecoder) } } impl RawDecoder for ASCIIDecoder { - fn from_self(&self) -> Box { ASCIIDecoder::new() } + fn from_self(&self) -> Box { ASCIIDecoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { output.writer_hint(input.len()); - fn write_ascii_bytes(output: &mut StringWriter, buf: &[u8]) { + fn write_ascii_bytes(output: &mut dyn StringWriter, buf: &[u8]) { output.write_str(unsafe {mem::transmute(buf)}); } @@ -91,7 +91,7 @@ impl RawDecoder for ASCIIDecoder { } } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { None } } diff --git a/src/codec/error.rs b/src/codec/error.rs index abf41b29..b7076db0 100644 --- a/src/codec/error.rs +++ b/src/codec/error.rs @@ -13,8 +13,8 @@ pub struct ErrorEncoding; impl Encoding for ErrorEncoding { fn name(&self) -> &'static str { "error" } - fn raw_encoder(&self) -> Box { ErrorEncoder::new() } - fn raw_decoder(&self) -> Box { ErrorDecoder::new() } + fn raw_encoder(&self) -> Box { ErrorEncoder::new() } + fn raw_decoder(&self) -> Box { ErrorDecoder::new() } } /// An encoder that always returns error. @@ -22,13 +22,13 @@ impl Encoding for ErrorEncoding { pub struct ErrorEncoder; impl ErrorEncoder { - pub fn new() -> Box { Box::new(ErrorEncoder) } + pub fn new() -> Box { Box::new(ErrorEncoder) } } impl RawEncoder for ErrorEncoder { - fn from_self(&self) -> Box { ErrorEncoder::new() } + fn from_self(&self) -> Box { ErrorEncoder::new() } - fn raw_feed(&mut self, input: &str, _output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, _output: &mut dyn ByteWriter) -> (usize, Option) { if let Some(ch) = input.chars().next() { (0, Some(CodecError { upto: ch.len_utf8() as isize, cause: "unrepresentable character".into() })) @@ -37,7 +37,7 @@ impl RawEncoder for ErrorEncoder { } } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -47,14 +47,14 @@ impl RawEncoder for ErrorEncoder { pub struct ErrorDecoder; impl ErrorDecoder { - pub fn new() -> Box { Box::new(ErrorDecoder) } + pub fn new() -> Box { Box::new(ErrorDecoder) } } impl RawDecoder for ErrorDecoder { - fn from_self(&self) -> Box { ErrorDecoder::new() } + fn from_self(&self) -> Box { ErrorDecoder::new() } fn raw_feed(&mut self, - input: &[u8], _output: &mut StringWriter) -> (usize, Option) { + input: &[u8], _output: &mut dyn StringWriter) -> (usize, Option) { if input.len() > 0 { (0, Some(CodecError { upto: 1, cause: "invalid sequence".into() })) } else { @@ -62,7 +62,7 @@ impl RawDecoder for ErrorDecoder { } } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { None } } diff --git a/src/codec/japanese.rs b/src/codec/japanese.rs index 50eff784..615bb75c 100644 --- a/src/codec/japanese.rs +++ b/src/codec/japanese.rs @@ -32,8 +32,8 @@ pub struct EUCJPEncoding; impl Encoding for EUCJPEncoding { fn name(&self) -> &'static str { "euc-jp" } fn whatwg_name(&self) -> Option<&'static str> { Some("euc-jp") } - fn raw_encoder(&self) -> Box { EUCJPEncoder::new() } - fn raw_decoder(&self) -> Box { EUCJP0212Decoder::new() } + fn raw_encoder(&self) -> Box { EUCJPEncoder::new() } + fn raw_decoder(&self) -> Box { EUCJP0212Decoder::new() } } /// An encoder for EUC-JP with unused G3 character set. @@ -41,22 +41,22 @@ impl Encoding for EUCJPEncoding { pub struct EUCJPEncoder; impl EUCJPEncoder { - pub fn new() -> Box { Box::new(EUCJPEncoder) } + pub fn new() -> Box { Box::new(EUCJPEncoder) } } impl RawEncoder for EUCJPEncoder { - fn from_self(&self) -> Box { EUCJPEncoder::new() } + fn from_self(&self) -> Box { EUCJPEncoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for ((i,j), ch) in input.index_iter() { match ch { - '\u{0}'...'\u{7f}' => { output.write_byte(ch as u8); } + '\u{0}'..='\u{7f}' => { output.write_byte(ch as u8); } '\u{a5}' => { output.write_byte(0x5c); } '\u{203e}' => { output.write_byte(0x7e); } - '\u{ff61}'...'\u{ff9f}' => { + '\u{ff61}'..='\u{ff9f}' => { output.write_byte(0x8e); output.write_byte((ch as usize - 0xff61 + 0xa1) as u8); } @@ -78,7 +78,7 @@ impl RawEncoder for EUCJPEncoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -90,22 +90,22 @@ struct EUCJP0212Decoder { } impl EUCJP0212Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(EUCJP0212Decoder { st: Default::default() }) } } impl RawDecoder for EUCJP0212Decoder { - fn from_self(&self) -> Box { EUCJP0212Decoder::new() } + fn from_self(&self) -> Box { EUCJP0212Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = eucjp::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = eucjp::raw_finish(self.st, output, &()); self.st = st; err @@ -121,7 +121,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0xa1...0xfe, 0xa1...0xfe) => (lead - 0xa1) * 94 + trail - 0xa1, + (0xa1..=0xfe, 0xa1..=0xfe) => (lead - 0xa1) * 94 + trail - 0xa1, _ => 0xffff, }; index::jis0208::forward(index) @@ -133,7 +133,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0xa1...0xfe, 0xa1...0xfe) => (lead - 0xa1) * 94 + trail - 0xa1, + (0xa1..=0xfe, 0xa1..=0xfe) => (lead - 0xa1) * 94 + trail - 0xa1, _ => 0xffff, }; index::jis0212::forward(index) @@ -142,32 +142,32 @@ stateful_decoder! { initial: // euc-jp lead = 0x00 state S0(ctx: Context) { - case b @ 0x00...0x7f => ctx.emit(b as u32); + case b @ 0x00..=0x7f => ctx.emit(b as u32); case 0x8e => S1(ctx); case 0x8f => S2(ctx); - case b @ 0xa1...0xfe => S3(ctx, b); + case b @ 0xa1..=0xfe => S3(ctx, b); case _ => ctx.err("invalid sequence"); } transient: // euc-jp lead = 0x8e state S1(ctx: Context) { - case b @ 0xa1...0xdf => ctx.emit(0xff61 + b as u32 - 0xa1); - case 0xa1...0xfe => ctx.err("invalid sequence"); + case b @ 0xa1..=0xdf => ctx.emit(0xff61 + b as u32 - 0xa1); + case 0xa1..=0xfe => ctx.err("invalid sequence"); case _ => ctx.backup_and_err(1, "invalid sequence"); } // euc-jp lead = 0x8f // JIS X 0201 half-width katakana state S2(ctx: Context) { - case b @ 0xa1...0xfe => S4(ctx, b); + case b @ 0xa1..=0xfe => S4(ctx, b); case _ => ctx.backup_and_err(1, "invalid sequence"); } // euc-jp lead != 0x00, euc-jp jis0212 flag = unset // JIS X 0208 two-byte sequence state S3(ctx: Context, lead: u8) { - case b @ 0xa1...0xfe => match map_two_0208_bytes(lead, b) { + case b @ 0xa1..=0xfe => match map_two_0208_bytes(lead, b) { // do NOT backup, we only backup for out-of-range trails. 0xffff => ctx.err("invalid sequence"), ch => ctx.emit(ch as u32) @@ -178,7 +178,7 @@ transient: // euc-jp lead != 0x00, euc-jp jis0212 flag = set // JIS X 0212 three-byte sequence state S4(ctx: Context, lead: u8) { - case b @ 0xa1...0xfe => match map_two_0212_bytes(lead, b) { + case b @ 0xa1..=0xfe => match map_two_0212_bytes(lead, b) { // do NOT backup, we only backup for out-of-range trails. 0xffff => ctx.err("invalid sequence"), ch => ctx.emit(ch as u32) @@ -452,8 +452,8 @@ pub struct Windows31JEncoding; impl Encoding for Windows31JEncoding { fn name(&self) -> &'static str { "windows-31j" } fn whatwg_name(&self) -> Option<&'static str> { Some("shift_jis") } // WHATWG compatibility - fn raw_encoder(&self) -> Box { Windows31JEncoder::new() } - fn raw_decoder(&self) -> Box { Windows31JDecoder::new() } + fn raw_encoder(&self) -> Box { Windows31JEncoder::new() } + fn raw_decoder(&self) -> Box { Windows31JDecoder::new() } } /// An encoder for Shift_JIS with IBM/NEC extensions. @@ -461,22 +461,22 @@ impl Encoding for Windows31JEncoding { pub struct Windows31JEncoder; impl Windows31JEncoder { - pub fn new() -> Box { Box::new(Windows31JEncoder) } + pub fn new() -> Box { Box::new(Windows31JEncoder) } } impl RawEncoder for Windows31JEncoder { - fn from_self(&self) -> Box { Windows31JEncoder::new() } + fn from_self(&self) -> Box { Windows31JEncoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for ((i,j), ch) in input.index_iter() { match ch { - '\u{0}'...'\u{80}' => { output.write_byte(ch as u8); } + '\u{0}'..='\u{80}' => { output.write_byte(ch as u8); } '\u{a5}' => { output.write_byte(0x5c); } '\u{203e}' => { output.write_byte(0x7e); } - '\u{ff61}'...'\u{ff9f}' => { + '\u{ff61}'..='\u{ff9f}' => { output.write_byte((ch as usize - 0xff61 + 0xa1) as u8); } _ => { @@ -500,7 +500,7 @@ impl RawEncoder for Windows31JEncoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -512,22 +512,22 @@ struct Windows31JDecoder { } impl Windows31JDecoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(Windows31JDecoder { st: Default::default() }) } } impl RawDecoder for Windows31JDecoder { - fn from_self(&self) -> Box { Windows31JDecoder::new() } + fn from_self(&self) -> Box { Windows31JDecoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = windows31j::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = windows31j::raw_finish(self.st, output, &()); self.st = st; err @@ -545,10 +545,10 @@ stateful_decoder! { let leadoffset = if lead < 0xa0 {0x81} else {0xc1}; let trailoffset = if trail < 0x7f {0x40} else {0x41}; let index = match (lead, trail) { - (0xf0...0xf9, 0x40...0x7e) | (0xf0...0xf9, 0x80...0xfc) => + (0xf0..=0xf9, 0x40..=0x7e) | (0xf0..=0xf9, 0x80..=0xfc) => return (0xe000 + (lead - 0xf0) * 188 + trail - trailoffset) as u32, - (0x81...0x9f, 0x40...0x7e) | (0x81...0x9f, 0x80...0xfc) | - (0xe0...0xfc, 0x40...0x7e) | (0xe0...0xfc, 0x80...0xfc) => + (0x81..=0x9f, 0x40..=0x7e) | (0x81..=0x9f, 0x80..=0xfc) | + (0xe0..=0xfc, 0x40..=0x7e) | (0xe0..=0xfc, 0x80..=0xfc) => (lead - leadoffset) * 188 + trail - trailoffset, _ => 0xffff, }; @@ -558,9 +558,9 @@ stateful_decoder! { initial: // shift_jis lead = 0x00 state S0(ctx: Context) { - case b @ 0x00...0x80 => ctx.emit(b as u32); - case b @ 0xa1...0xdf => ctx.emit(0xff61 + b as u32 - 0xa1); - case b @ 0x81...0x9f, b @ 0xe0...0xfc => S1(ctx, b); + case b @ 0x00..=0x80 => ctx.emit(b as u32); + case b @ 0xa1..=0xdf => ctx.emit(0xff61 + b as u32 - 0xa1); + case b @ 0x81..=0x9f, b @ 0xe0..=0xfc => S1(ctx, b); case _ => ctx.err("invalid sequence"); } @@ -774,8 +774,8 @@ pub struct ISO2022JPEncoding; impl Encoding for ISO2022JPEncoding { fn name(&self) -> &'static str { "iso-2022-jp" } fn whatwg_name(&self) -> Option<&'static str> { Some("iso-2022-jp") } - fn raw_encoder(&self) -> Box { ISO2022JPEncoder::new() } - fn raw_decoder(&self) -> Box { ISO2022JPDecoder::new() } + fn raw_encoder(&self) -> Box { ISO2022JPEncoder::new() } + fn raw_decoder(&self) -> Box { ISO2022JPDecoder::new() } } #[derive(PartialEq,Clone,Copy)] @@ -792,14 +792,14 @@ pub struct ISO2022JPEncoder { } impl ISO2022JPEncoder { - pub fn new() -> Box { Box::new(ISO2022JPEncoder { st: ASCII }) } + pub fn new() -> Box { Box::new(ISO2022JPEncoder { st: ASCII }) } } impl RawEncoder for ISO2022JPEncoder { - fn from_self(&self) -> Box { ISO2022JPEncoder::new() } + fn from_self(&self) -> Box { ISO2022JPEncoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); let mut st = self.st; @@ -815,10 +815,10 @@ impl RawEncoder for ISO2022JPEncoder { for ((i,j), ch) in input.index_iter() { match ch { - '\u{0}'...'\u{7f}' => { ensure_ASCII!(); output.write_byte(ch as u8); } + '\u{0}'..='\u{7f}' => { ensure_ASCII!(); output.write_byte(ch as u8); } '\u{a5}' => { ensure_ASCII!(); output.write_byte(0x5c); } '\u{203e}' => { ensure_ASCII!(); output.write_byte(0x7e); } - '\u{ff61}'...'\u{ff9f}' => { + '\u{ff61}'..='\u{ff9f}' => { ensure_Katakana!(); output.write_byte((ch as usize - 0xff61 + 0x21) as u8); } @@ -844,7 +844,7 @@ impl RawEncoder for ISO2022JPEncoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -856,22 +856,22 @@ struct ISO2022JPDecoder { } impl ISO2022JPDecoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(ISO2022JPDecoder { st: Default::default() }) } } impl RawDecoder for ISO2022JPDecoder { - fn from_self(&self) -> Box { ISO2022JPDecoder::new() } + fn from_self(&self) -> Box { ISO2022JPDecoder::new() } fn is_ascii_compatible(&self) -> bool { false } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = iso2022jp::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = iso2022jp::raw_finish(self.st, output, &()); self.st = st; err @@ -887,7 +887,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x21...0x7e, 0x21...0x7e) => (lead - 0x21) * 94 + trail - 0x21, + (0x21..=0x7e, 0x21..=0x7e) => (lead - 0x21) * 94 + trail - 0x21, _ => 0xffff, }; index::jis0208::forward(index) @@ -899,7 +899,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x21...0x7e, 0x21...0x7e) => (lead - 0x21) * 94 + trail - 0x21, + (0x21..=0x7e, 0x21..=0x7e) => (lead - 0x21) * 94 + trail - 0x21, _ => 0xffff, }; index::jis0212::forward(index) @@ -909,7 +909,7 @@ initial: // iso-2022-jp state = ASCII, iso-2022-jp jis0212 flag = unset, iso-2022-jp lead = 0x00 state ASCII(ctx: Context) { case 0x1b => EscapeStart(ctx); - case b @ 0x00...0x7f => ctx.emit(b as u32), ASCII(ctx); + case b @ 0x00..=0x7f => ctx.emit(b as u32), ASCII(ctx); case _ => ctx.err("invalid sequence"), ASCII(ctx); final => ctx.reset(); } @@ -934,7 +934,7 @@ checkpoint: // iso-2022-jp state = Katakana state Katakana(ctx: Context) { case 0x1b => EscapeStart(ctx); - case b @ 0x21...0x5f => ctx.emit(0xff61 + b as u32 - 0x21), Katakana(ctx); + case b @ 0x21..=0x5f => ctx.emit(0xff61 + b as u32 - 0x21), Katakana(ctx); case _ => ctx.err("invalid sequence"), Katakana(ctx); final => ctx.reset(); } diff --git a/src/codec/korean.rs b/src/codec/korean.rs index 7fb3b119..cf879d57 100644 --- a/src/codec/korean.rs +++ b/src/codec/korean.rs @@ -27,8 +27,8 @@ pub struct Windows949Encoding; impl Encoding for Windows949Encoding { fn name(&self) -> &'static str { "windows-949" } fn whatwg_name(&self) -> Option<&'static str> { Some("euc-kr") } // WHATWG compatibility - fn raw_encoder(&self) -> Box { Windows949Encoder::new() } - fn raw_decoder(&self) -> Box { Windows949Decoder::new() } + fn raw_encoder(&self) -> Box { Windows949Encoder::new() } + fn raw_decoder(&self) -> Box { Windows949Decoder::new() } } /// An encoder for Windows code page 949. @@ -36,14 +36,14 @@ impl Encoding for Windows949Encoding { pub struct Windows949Encoder; impl Windows949Encoder { - pub fn new() -> Box { Box::new(Windows949Encoder) } + pub fn new() -> Box { Box::new(Windows949Encoder) } } impl RawEncoder for Windows949Encoder { - fn from_self(&self) -> Box { Windows949Encoder::new() } + fn from_self(&self) -> Box { Windows949Encoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for ((i,j), ch) in input.index_iter() { @@ -64,7 +64,7 @@ impl RawEncoder for Windows949Encoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -76,22 +76,22 @@ struct Windows949Decoder { } impl Windows949Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(Windows949Decoder { st: Default::default() }) } } impl RawDecoder for Windows949Decoder { - fn from_self(&self) -> Box { Windows949Decoder::new() } + fn from_self(&self) -> Box { Windows949Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = windows949::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = windows949::raw_finish(self.st, output, &()); self.st = st; err @@ -107,7 +107,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x81...0xfe, 0x41...0xfe) => (lead - 0x81) * 190 + (trail - 0x41), + (0x81..=0xfe, 0x41..=0xfe) => (lead - 0x81) * 190 + (trail - 0x41), (_, _) => 0xffff, }; index::euc_kr::forward(index) @@ -116,8 +116,8 @@ stateful_decoder! { initial: // euc-kr lead = 0x00 state S0(ctx: Context) { - case b @ 0x00...0x7f => ctx.emit(b as u32); - case b @ 0x81...0xfe => S1(ctx, b); + case b @ 0x00..=0x7f => ctx.emit(b as u32); + case b @ 0x81..=0xfe => S1(ctx, b); case _ => ctx.err("invalid sequence"); } diff --git a/src/codec/simpchinese.rs b/src/codec/simpchinese.rs index e7d6b210..b14580c6 100644 --- a/src/codec/simpchinese.rs +++ b/src/codec/simpchinese.rs @@ -40,8 +40,8 @@ pub struct GB18030Encoding; impl Encoding for GB18030Encoding { fn name(&self) -> &'static str { "gb18030" } fn whatwg_name(&self) -> Option<&'static str> { Some("gb18030") } - fn raw_encoder(&self) -> Box { GB18030Encoder::new() } - fn raw_decoder(&self) -> Box { GB18030Decoder::new() } + fn raw_encoder(&self) -> Box { GB18030Encoder::new() } + fn raw_decoder(&self) -> Box { GB18030Decoder::new() } } /// An encoder for GB 18030. @@ -49,16 +49,16 @@ impl Encoding for GB18030Encoding { pub struct GB18030Encoder; impl GB18030Encoder { - pub fn new() -> Box { Box::new(GB18030Encoder) } + pub fn new() -> Box { Box::new(GB18030Encoder) } } impl RawEncoder for GB18030Encoder { - fn from_self(&self) -> Box { GB18030Encoder::new() } + fn from_self(&self) -> Box { GB18030Encoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { GBEncoder.raw_feed(input, output, false) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { None } + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } /// GBK, as a subset of GB 18030. @@ -84,8 +84,8 @@ pub struct GBKEncoding; impl Encoding for GBKEncoding { fn name(&self) -> &'static str { "gbk" } fn whatwg_name(&self) -> Option<&'static str> { Some("gbk") } - fn raw_encoder(&self) -> Box { GBKEncoder::new() } - fn raw_decoder(&self) -> Box { GB18030Decoder::new() } + fn raw_encoder(&self) -> Box { GBKEncoder::new() } + fn raw_decoder(&self) -> Box { GB18030Decoder::new() } } /// An encoder for GBK. @@ -93,16 +93,16 @@ impl Encoding for GBKEncoding { pub struct GBKEncoder; impl GBKEncoder { - pub fn new() -> Box { Box::new(GBKEncoder) } + pub fn new() -> Box { Box::new(GBKEncoder) } } impl RawEncoder for GBKEncoder { - fn from_self(&self) -> Box { GBKEncoder::new() } + fn from_self(&self) -> Box { GBKEncoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { GBEncoder.raw_feed(input, output, true) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { None } + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } /// A shared encoder logic for GBK and GB 18030. @@ -110,7 +110,7 @@ impl RawEncoder for GBKEncoder { struct GBEncoder; impl GBEncoder { - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter, + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter, gbk_flag: bool) -> (usize, Option) { output.writer_hint(input.len()); @@ -162,22 +162,22 @@ struct GB18030Decoder { } impl GB18030Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(GB18030Decoder { st: Default::default() }) } } impl RawDecoder for GB18030Decoder { - fn from_self(&self) -> Box { GB18030Decoder::new() } + fn from_self(&self) -> Box { GB18030Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = gb18030::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = gb18030::raw_finish(self.st, output, &()); self.st = st; err @@ -193,7 +193,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x81...0xfe, 0x40...0x7e) | (0x81...0xfe, 0x80...0xfe) => { + (0x81..=0xfe, 0x40..=0x7e) | (0x81..=0xfe, 0x80..=0xfe) => { let trailoffset = if trail < 0x7f {0x40} else {0x41}; (lead - 0x81) * 190 + trail - trailoffset } @@ -214,16 +214,16 @@ stateful_decoder! { initial: // gb18030 first = 0x00, gb18030 second = 0x00, gb18030 third = 0x00 state S0(ctx: Context) { - case b @ 0x00...0x7f => ctx.emit(b as u32); + case b @ 0x00..=0x7f => ctx.emit(b as u32); case 0x80 => ctx.emit(0x20ac); - case b @ 0x81...0xfe => S1(ctx, b); + case b @ 0x81..=0xfe => S1(ctx, b); case _ => ctx.err("invalid sequence"); } transient: // gb18030 first != 0x00, gb18030 second = 0x00, gb18030 third = 0x00 state S1(ctx: Context, first: u8) { - case b @ 0x30...0x39 => S2(ctx, first, b); + case b @ 0x30..=0x39 => S2(ctx, first, b); case b => match map_two_bytes(first, b) { 0xffff => ctx.backup_and_err(1, "invalid sequence"), // unconditional ch => ctx.emit(ch) @@ -232,13 +232,13 @@ transient: // gb18030 first != 0x00, gb18030 second != 0x00, gb18030 third = 0x00 state S2(ctx: Context, first: u8, second: u8) { - case b @ 0x81...0xfe => S3(ctx, first, second, b); + case b @ 0x81..=0xfe => S3(ctx, first, second, b); case _ => ctx.backup_and_err(2, "invalid sequence"); } // gb18030 first != 0x00, gb18030 second != 0x00, gb18030 third != 0x00 state S3(ctx: Context, first: u8, second: u8, third: u8) { - case b @ 0x30...0x39 => match map_four_bytes(first, second, third, b) { + case b @ 0x30..=0x39 => match map_four_bytes(first, second, third, b) { 0xffffffff => ctx.backup_and_err(3, "invalid sequence"), // unconditional ch => ctx.emit(ch) }; @@ -479,8 +479,8 @@ pub struct HZEncoding; impl Encoding for HZEncoding { fn name(&self) -> &'static str { "hz" } fn whatwg_name(&self) -> Option<&'static str> { None } - fn raw_encoder(&self) -> Box { HZEncoder::new() } - fn raw_decoder(&self) -> Box { HZDecoder::new() } + fn raw_encoder(&self) -> Box { HZEncoder::new() } + fn raw_decoder(&self) -> Box { HZDecoder::new() } } /// An encoder for HZ. @@ -490,14 +490,14 @@ pub struct HZEncoder { } impl HZEncoder { - pub fn new() -> Box { Box::new(HZEncoder { escaped: false }) } + pub fn new() -> Box { Box::new(HZEncoder { escaped: false }) } } impl RawEncoder for HZEncoder { - fn from_self(&self) -> Box { HZEncoder::new() } + fn from_self(&self) -> Box { HZEncoder::new() } fn is_ascii_compatible(&self) -> bool { false } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); let mut escaped = self.escaped; @@ -541,7 +541,7 @@ impl RawEncoder for HZEncoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -553,22 +553,22 @@ struct HZDecoder { } impl HZDecoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(HZDecoder { st: Default::default() }) } } impl RawDecoder for HZDecoder { - fn from_self(&self) -> Box { HZDecoder::new() } + fn from_self(&self) -> Box { HZDecoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = hz::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = hz::raw_finish(self.st, output, &()); self.st = st; err @@ -584,7 +584,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x20...0x7f, 0x21...0x7e) => (lead - 1) * 190 + (trail + 0x3f), + (0x20..=0x7f, 0x21..=0x7e) => (lead - 1) * 190 + (trail + 0x3f), _ => 0xffff, }; index::gb18030::forward(index) @@ -594,7 +594,7 @@ initial: // hz-gb-2312 flag = unset, hz-gb-2312 lead = 0x00 state A0(ctx: Context) { case 0x7e => A1(ctx); - case b @ 0x00...0x7f => ctx.emit(b as u32); + case b @ 0x00..=0x7f => ctx.emit(b as u32); case _ => ctx.err("invalid sequence"); final => ctx.reset(); } @@ -603,7 +603,7 @@ checkpoint: // hz-gb-2312 flag = set, hz-gb-2312 lead = 0x00 state B0(ctx: Context) { case 0x7e => B1(ctx); - case b @ 0x20...0x7f => B2(ctx, b); + case b @ 0x20..=0x7f => B2(ctx, b); case 0x0a => ctx.err("invalid sequence"); // error *and* reset case _ => ctx.err("invalid sequence"), B0(ctx); final => ctx.reset(); diff --git a/src/codec/singlebyte.rs b/src/codec/singlebyte.rs index 713eee1b..0f0c2094 100644 --- a/src/codec/singlebyte.rs +++ b/src/codec/singlebyte.rs @@ -20,8 +20,8 @@ pub struct SingleByteEncoding { impl Encoding for SingleByteEncoding { fn name(&self) -> &'static str { self.name } fn whatwg_name(&self) -> Option<&'static str> { self.whatwg_name } - fn raw_encoder(&self) -> Box { SingleByteEncoder::new(self.index_backward) } - fn raw_decoder(&self) -> Box { SingleByteDecoder::new(self.index_forward) } + fn raw_encoder(&self) -> Box { SingleByteEncoder::new(self.index_backward) } + fn raw_decoder(&self) -> Box { SingleByteDecoder::new(self.index_forward) } } /// An encoder for single-byte encodings based on ASCII. @@ -31,16 +31,16 @@ pub struct SingleByteEncoder { } impl SingleByteEncoder { - pub fn new(index_backward: extern "Rust" fn(u32) -> u8) -> Box { + pub fn new(index_backward: extern "Rust" fn(u32) -> u8) -> Box { Box::new(SingleByteEncoder { index_backward: index_backward }) } } impl RawEncoder for SingleByteEncoder { - fn from_self(&self) -> Box { SingleByteEncoder::new(self.index_backward) } + fn from_self(&self) -> Box { SingleByteEncoder::new(self.index_backward) } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for ((i,j), ch) in input.index_iter() { @@ -61,7 +61,7 @@ impl RawEncoder for SingleByteEncoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -73,16 +73,16 @@ pub struct SingleByteDecoder { } impl SingleByteDecoder { - pub fn new(index_forward: extern "Rust" fn(u8) -> u16) -> Box { + pub fn new(index_forward: extern "Rust" fn(u8) -> u16) -> Box { Box::new(SingleByteDecoder { index_forward: index_forward }) } } impl RawDecoder for SingleByteDecoder { - fn from_self(&self) -> Box { SingleByteDecoder::new(self.index_forward) } + fn from_self(&self) -> Box { SingleByteDecoder::new(self.index_forward) } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { output.writer_hint(input.len()); let mut i = 0; @@ -105,7 +105,7 @@ impl RawDecoder for SingleByteDecoder { (i, None) } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { None } } diff --git a/src/codec/tradchinese.rs b/src/codec/tradchinese.rs index 41748b76..82236ef4 100644 --- a/src/codec/tradchinese.rs +++ b/src/codec/tradchinese.rs @@ -30,8 +30,8 @@ pub struct BigFive2003Encoding; impl Encoding for BigFive2003Encoding { fn name(&self) -> &'static str { "big5-2003" } fn whatwg_name(&self) -> Option<&'static str> { Some("big5") } // WHATWG compatibility - fn raw_encoder(&self) -> Box { BigFive2003Encoder::new() } - fn raw_decoder(&self) -> Box { BigFive2003HKSCS2008Decoder::new() } + fn raw_encoder(&self) -> Box { BigFive2003Encoder::new() } + fn raw_decoder(&self) -> Box { BigFive2003HKSCS2008Decoder::new() } } /// An encoder for Big5-2003. @@ -39,14 +39,14 @@ impl Encoding for BigFive2003Encoding { pub struct BigFive2003Encoder; impl BigFive2003Encoder { - pub fn new() -> Box { Box::new(BigFive2003Encoder) } + pub fn new() -> Box { Box::new(BigFive2003Encoder) } } impl RawEncoder for BigFive2003Encoder { - fn from_self(&self) -> Box { BigFive2003Encoder::new() } + fn from_self(&self) -> Box { BigFive2003Encoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for ((i,j), ch) in input.index_iter() { @@ -69,7 +69,7 @@ impl RawEncoder for BigFive2003Encoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -81,22 +81,22 @@ struct BigFive2003HKSCS2008Decoder { } impl BigFive2003HKSCS2008Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(BigFive2003HKSCS2008Decoder { st: Default::default() }) } } impl RawDecoder for BigFive2003HKSCS2008Decoder { - fn from_self(&self) -> Box { BigFive2003HKSCS2008Decoder::new() } + fn from_self(&self) -> Box { BigFive2003HKSCS2008Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { let (st, processed, err) = bigfive2003::raw_feed(self.st, input, output, &()); self.st = st; (processed, err) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { let (st, err) = bigfive2003::raw_finish(self.st, output, &()); self.st = st; err @@ -112,7 +112,7 @@ stateful_decoder! { let lead = lead as u16; let trail = trail as u16; let index = match (lead, trail) { - (0x81...0xfe, 0x40...0x7e) | (0x81...0xfe, 0xa1...0xfe) => { + (0x81..=0xfe, 0x40..=0x7e) | (0x81..=0xfe, 0xa1..=0xfe) => { let trailoffset = if trail < 0x7f {0x40} else {0x62}; (lead - 0x81) * 157 + trail - trailoffset } @@ -124,8 +124,8 @@ stateful_decoder! { initial: // big5 lead = 0x00 state S0(ctx: Context) { - case b @ 0x00...0x7f => ctx.emit(b as u32); - case b @ 0x81...0xfe => S1(ctx, b); + case b @ 0x00..=0x7f => ctx.emit(b as u32); + case b @ 0x81..=0xfe => S1(ctx, b); case _ => ctx.err("invalid sequence"); } diff --git a/src/codec/utf_16.rs b/src/codec/utf_16.rs index 201e1935..1b250bf5 100644 --- a/src/codec/utf_16.rs +++ b/src/codec/utf_16.rs @@ -22,8 +22,8 @@ pub struct UTF16LEEncoding; impl Encoding for UTF16LEEncoding { fn name(&self) -> &'static str { "utf-16le" } fn whatwg_name(&self) -> Option<&'static str> { Some("utf-16le") } - fn raw_encoder(&self) -> Box { UTF16LEEncoder::new() } - fn raw_decoder(&self) -> Box { UTF16LEDecoder::new() } + fn raw_encoder(&self) -> Box { UTF16LEEncoder::new() } + fn raw_decoder(&self) -> Box { UTF16LEDecoder::new() } } /// UTF-16 (UCS Transformation Format, 16-bit), in big endian. @@ -40,8 +40,8 @@ pub struct UTF16BEEncoding; impl Encoding for UTF16BEEncoding { fn name(&self) -> &'static str { "utf-16be" } fn whatwg_name(&self) -> Option<&'static str> { Some("utf-16be") } - fn raw_encoder(&self) -> Box { UTF16BEEncoder::new() } - fn raw_decoder(&self) -> Box { UTF16BEDecoder::new() } + fn raw_encoder(&self) -> Box { UTF16BEEncoder::new() } + fn raw_decoder(&self) -> Box { UTF16BEDecoder::new() } } /// A shared encoder logic for UTF-16. @@ -49,18 +49,18 @@ impl Encoding for UTF16BEEncoding { struct UTF16Encoder; impl UTF16Encoder { - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter, + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter, write_two_bytes: F) -> (usize, Option) - where F: Fn(&mut ByteWriter, u8, u8) { + where F: Fn(&mut dyn ByteWriter, u8, u8) { output.writer_hint(input.len() * 2); for ch in input.chars() { match ch { - '\u{0}'...'\u{d7ff}' | '\u{e000}'...'\u{ffff}' => { + '\u{0}'..='\u{d7ff}' | '\u{e000}'..='\u{ffff}' => { let ch = ch as u32; write_two_bytes(output, (ch >> 8) as u8, (ch & 0xff) as u8); } - '\u{10000}'...'\u{10ffff}' => { + '\u{10000}'..='\u{10ffff}' => { let ch = ch as u32 - 0x10000; write_two_bytes(output, (0xd8 | (ch >> 18)) as u8, ((ch >> 10) & 0xff) as u8); @@ -79,18 +79,18 @@ impl UTF16Encoder { pub struct UTF16LEEncoder; impl UTF16LEEncoder { - fn new() -> Box { Box::new(UTF16LEEncoder) } + fn new() -> Box { Box::new(UTF16LEEncoder) } } impl RawEncoder for UTF16LEEncoder { - fn from_self(&self) -> Box { UTF16LEEncoder::new() } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { - UTF16Encoder.raw_feed(input, output, |output: &mut ByteWriter, msb: u8, lsb: u8| { + fn from_self(&self) -> Box { UTF16LEEncoder::new() } + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { + UTF16Encoder.raw_feed(input, output, |output: &mut dyn ByteWriter, msb: u8, lsb: u8| { output.write_byte(lsb); output.write_byte(msb); }) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { None } + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } /// An encoder for UTF-16 in big endian. @@ -98,18 +98,18 @@ impl RawEncoder for UTF16LEEncoder { pub struct UTF16BEEncoder; impl UTF16BEEncoder { - fn new() -> Box { Box::new(UTF16BEEncoder) } + fn new() -> Box { Box::new(UTF16BEEncoder) } } impl RawEncoder for UTF16BEEncoder { - fn from_self(&self) -> Box { UTF16BEEncoder::new() } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { - UTF16Encoder.raw_feed(input, output, |output: &mut ByteWriter, msb: u8, lsb: u8| { + fn from_self(&self) -> Box { UTF16BEEncoder::new() } + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { + UTF16Encoder.raw_feed(input, output, |output: &mut dyn ByteWriter, msb: u8, lsb: u8| { output.write_byte(msb); output.write_byte(lsb); }) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { None } + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } /// A shared decoder logic for UTF-16. @@ -124,7 +124,7 @@ impl UTF16Decoder { UTF16Decoder { leadbyte: 0xffff, leadsurrogate: 0xffff } } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter, + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter, concat_two_bytes: F) -> (usize, Option) where F: Fn(u16, u8) -> u16 { output.writer_hint(input.len() / 2); // when every codepoint is U+0000..007F @@ -143,7 +143,7 @@ impl UTF16Decoder { let upper = self.leadsurrogate; self.leadsurrogate = 0xffff; match ch { - 0xdc00...0xdfff => { + 0xdc00..=0xdfff => { let ch = ((upper as u32 - 0xd800) << 10) + (ch as u32 - 0xdc00); output.write_char(as_char(ch + 0x10000)); processed = i; @@ -156,11 +156,11 @@ impl UTF16Decoder { } } else { match ch { - 0xd800...0xdbff => { + 0xd800..=0xdbff => { self.leadsurrogate = ch; // pass through } - 0xdc00...0xdfff => { + 0xdc00..=0xdfff => { return (processed, Some(CodecError { upto: i as isize, cause: "invalid sequence".into() })); @@ -184,7 +184,7 @@ impl UTF16Decoder { let ch = concat_two_bytes(input[i-1] as u16, input[i]); i += 1; match ch { - 0xdc00...0xdfff => { + 0xdc00..=0xdfff => { let ch = ((upper as u32 - 0xd800) << 10) + (ch as u32 - 0xdc00); output.write_char(as_char(ch + 0x10000)); } @@ -209,7 +209,7 @@ impl UTF16Decoder { } let ch = concat_two_bytes(input[i-1] as u16, input[i]); match ch { - 0xd800...0xdbff => { + 0xd800..=0xdbff => { i += 2; if i >= len { self.leadsurrogate = ch; @@ -218,7 +218,7 @@ impl UTF16Decoder { } let ch2 = concat_two_bytes(input[i-1] as u16, input[i]); match ch2 { - 0xdc00...0xdfff => { + 0xdc00..=0xdfff => { let ch = ((ch as u32 - 0xd800) << 10) + (ch2 as u32 - 0xdc00); output.write_char(as_char(ch + 0x10000)); } @@ -229,7 +229,7 @@ impl UTF16Decoder { } } } - 0xdc00...0xdfff => { + 0xdc00..=0xdfff => { return (processed, Some(CodecError { upto: i as isize + 1, cause: "invalid sequence".into() })); @@ -244,7 +244,7 @@ impl UTF16Decoder { (processed, None) } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { let leadbyte = self.leadbyte; let leadsurrogate = self.leadsurrogate; self.leadbyte = 0xffff; @@ -264,17 +264,17 @@ struct UTF16LEDecoder { } impl UTF16LEDecoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(UTF16LEDecoder { inner: UTF16Decoder::new() }) } } impl RawDecoder for UTF16LEDecoder { - fn from_self(&self) -> Box { UTF16LEDecoder::new() } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn from_self(&self) -> Box { UTF16LEDecoder::new() } + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { self.inner.raw_feed(input, output, |lead: u16, trail: u8| lead | ((trail as u16) << 8)) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { self.inner.raw_finish(output) } } @@ -286,17 +286,17 @@ struct UTF16BEDecoder { } impl UTF16BEDecoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(UTF16BEDecoder { inner: UTF16Decoder::new() }) } } impl RawDecoder for UTF16BEDecoder { - fn from_self(&self) -> Box { UTF16BEDecoder::new() } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn from_self(&self) -> Box { UTF16BEDecoder::new() } + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { self.inner.raw_feed(input, output, |lead: u16, trail: u8| (lead << 8) | trail as u16) } - fn raw_finish(&mut self, output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option { self.inner.raw_finish(output) } } diff --git a/src/codec/utf_8.rs b/src/codec/utf_8.rs index 5b307988..a0f4bd88 100644 --- a/src/codec/utf_8.rs +++ b/src/codec/utf_8.rs @@ -49,8 +49,8 @@ pub struct UTF8Encoding; impl Encoding for UTF8Encoding { fn name(&self) -> &'static str { "utf-8" } fn whatwg_name(&self) -> Option<&'static str> { Some("utf-8") } - fn raw_encoder(&self) -> Box { UTF8Encoder::new() } - fn raw_decoder(&self) -> Box { UTF8Decoder::new() } + fn raw_encoder(&self) -> Box { UTF8Encoder::new() } + fn raw_decoder(&self) -> Box { UTF8Decoder::new() } } /// An encoder for UTF-8. @@ -58,21 +58,21 @@ impl Encoding for UTF8Encoding { pub struct UTF8Encoder; impl UTF8Encoder { - pub fn new() -> Box { Box::new(UTF8Encoder) } + pub fn new() -> Box { Box::new(UTF8Encoder) } } impl RawEncoder for UTF8Encoder { - fn from_self(&self) -> Box { UTF8Encoder::new() } + fn from_self(&self) -> Box { UTF8Encoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { let input: &[u8] = input.as_bytes(); assert!(str::from_utf8(input).is_ok()); output.write_bytes(input); (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -86,7 +86,7 @@ pub struct UTF8Decoder { } impl UTF8Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(UTF8Decoder { queuelen: 0, queue: [0; 4], state: INITIAL_STATE }) } } @@ -139,13 +139,13 @@ macro_rules! next_state(($state:expr, $ch:expr) => ( )); impl RawDecoder for UTF8Decoder { - fn from_self(&self) -> Box { UTF8Decoder::new() } + fn from_self(&self) -> Box { UTF8Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { output.writer_hint(input.len()); - fn write_bytes(output: &mut StringWriter, bytes: &[u8]) { + fn write_bytes(output: &mut dyn StringWriter, bytes: &[u8]) { output.write_str(unsafe {mem::transmute(bytes)}); } @@ -194,7 +194,7 @@ impl RawDecoder for UTF8Decoder { (processed, None) } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { let state = self.state; let queuelen = self.queuelen; self.state = INITIAL_STATE; diff --git a/src/codec/whatwg.rs b/src/codec/whatwg.rs index 869c0099..e58e4051 100644 --- a/src/codec/whatwg.rs +++ b/src/codec/whatwg.rs @@ -15,8 +15,8 @@ pub struct EncoderOnlyUTF8Encoding; impl Encoding for EncoderOnlyUTF8Encoding { fn name(&self) -> &'static str { "encoder-only-utf-8" } fn whatwg_name(&self) -> Option<&'static str> { Some("replacement") } // WHATWG compatibility - fn raw_encoder(&self) -> Box { codec::utf_8::UTF8Encoding.raw_encoder() } - fn raw_decoder(&self) -> Box { codec::error::ErrorEncoding.raw_decoder() } + fn raw_encoder(&self) -> Box { codec::utf_8::UTF8Encoding.raw_encoder() } + fn raw_decoder(&self) -> Box { codec::error::ErrorEncoding.raw_decoder() } } /// Algorithmic mapping for `x-user-defined` encoding. diff --git a/src/label.rs b/src/label.rs index ccbf7a9d..c9762e10 100644 --- a/src/label.rs +++ b/src/label.rs @@ -12,7 +12,7 @@ use types::EncodingRef; pub fn encoding_from_whatwg_label(label: &str) -> Option { let label = label.trim_matches(&[' ', '\n', '\r', '\t', '\x0C'][..]); let label: String = - label.chars().map(|c| match c { 'A'...'Z' => (c as u8 + 32) as char, _ => c }).collect(); + label.chars().map(|c| match c { 'A'..='Z' => (c as u8 + 32) as char, _ => c }).collect(); match &label[..] { "unicode-1-1-utf-8" | "utf-8" | diff --git a/src/testutils.rs b/src/testutils.rs index cd48d696..7bc1338d 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -28,7 +28,7 @@ pub trait Testable { output: &'a Self::Output) -> TestResult<'a, Self::Output>; } -impl Testable for RawDecoder { +impl Testable for dyn RawDecoder { type Input = [u8]; type Output = str; @@ -89,7 +89,7 @@ impl Testable for RawDecoder { } } -impl Testable for RawEncoder { +impl Testable for dyn RawEncoder { type Input = str; type Output = [u8]; diff --git a/src/types.rs b/src/types.rs index b3e45a71..a837ab1a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -19,7 +19,7 @@ mod tests { // `e*ee*ease*l` where `*` is substituted by `prepend`) and prohibits `prohibit` character. struct MyEncoder { flag: bool, prohibit: char, prepend: &'static str, toggle: bool } impl RawEncoder for MyEncoder { - fn from_self(&self) -> Box { + fn from_self(&self) -> Box { Box::new(MyEncoder { flag: self.flag, prohibit: self.prohibit, prepend: self.prepend, @@ -27,7 +27,7 @@ mod tests { } fn is_ascii_compatible(&self) -> bool { self.flag } fn raw_feed(&mut self, input: &str, - output: &mut ByteWriter) -> (usize, Option) { + output: &mut dyn ByteWriter) -> (usize, Option) { for ((i,j), ch) in input.index_iter() { if ch <= '\u{7f}' && ch != self.prohibit { if self.toggle && !self.prepend.is_empty() { @@ -44,19 +44,19 @@ mod tests { } (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { None } + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } struct MyEncoding { flag: bool, prohibit: char, prepend: &'static str } impl Encoding for MyEncoding { fn name(&self) -> &'static str { "my encoding" } - fn raw_encoder(&self) -> Box { + fn raw_encoder(&self) -> Box { Box::new(MyEncoder { flag: self.flag, prohibit: self.prohibit, prepend: self.prepend, toggle: false }) } - fn raw_decoder(&self) -> Box { panic!("not supported") } + fn raw_decoder(&self) -> Box { panic!("not supported") } } #[test] @@ -67,7 +67,7 @@ mod tests { prepend: "", }; - assert_eq!(format!("{:?}", &enc as &Encoding), "Encoding(my encoding)"); + assert_eq!(format!("{:?}", &enc as &dyn Encoding), "Encoding(my encoding)"); } #[test] diff --git a/src/util.rs b/src/util.rs index 1d313aa7..8ac9d077 100644 --- a/src/util.rs +++ b/src/util.rs @@ -57,7 +57,7 @@ pub struct StatefulDecoderHelper<'a, St, Data: 'a> { /// The current index to the buffer. pub pos: usize, /// The output buffer. - pub output: &'a mut (types::StringWriter + 'a), + pub output: &'a mut (dyn types::StringWriter + 'a), /// The last codec error. The caller will later collect this. pub err: Option, /// The additional data attached for the use from transition functions. @@ -69,7 +69,7 @@ pub struct StatefulDecoderHelper<'a, St, Data: 'a> { impl<'a, St: Default, Data> StatefulDecoderHelper<'a, St, Data> { /// Makes a new decoder context out of given buffer and output callback. #[inline(always)] - pub fn new(buf: &'a [u8], output: &'a mut (types::StringWriter + 'a), + pub fn new(buf: &'a [u8], output: &'a mut (dyn types::StringWriter + 'a), data: &'a Data) -> StatefulDecoderHelper<'a, St, Data> { StatefulDecoderHelper { buf: buf, pos: 0, output: output, err: None, data: data, _marker: PhantomData } @@ -229,7 +229,7 @@ macro_rules! stateful_decoder { )* } - pub fn raw_feed(mut st: State, input: &[u8], output: &mut ::types::StringWriter, + pub fn raw_feed(mut st: State, input: &[u8], output: &mut dyn (::types::StringWriter), data: &T) -> (State, usize, Option<::types::CodecError>) { output.writer_hint(input.len()); @@ -271,7 +271,7 @@ macro_rules! stateful_decoder { (st, processed, None) } - pub fn raw_finish(mut st: State, output: &mut ::types::StringWriter, + pub fn raw_finish(mut st: State, output: &mut dyn (::types::StringWriter), data: &T) -> (State, Option<::types::CodecError>) { #![allow(unused_mut, unused_variables)] let mut ctx = ::util::StatefulDecoderHelper::new(&[], output, data); From f20d2ef1f740e13aa271bf6caa21fc66e36f2128 Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:48:25 -0500 Subject: [PATCH 2/9] cargo +nightly fix --edition --- src/all.rs | 10 +++++----- src/codec/ascii.rs | 6 +++--- src/codec/error.rs | 4 ++-- src/codec/japanese.rs | 28 ++++++++++++++-------------- src/codec/korean.rs | 12 ++++++------ src/codec/simpchinese.rs | 24 ++++++++++++------------ src/codec/singlebyte.rs | 8 ++++---- src/codec/tradchinese.rs | 12 ++++++------ src/codec/utf_16.rs | 6 +++--- src/codec/utf_8.rs | 26 +++++++++++++------------- src/codec/whatwg.rs | 4 ++-- src/label.rs | 6 +++--- src/lib.rs | 2 +- src/testutils.rs | 4 ++-- src/types.rs | 2 +- src/util.rs | 16 ++++++++-------- 16 files changed, 85 insertions(+), 85 deletions(-) diff --git a/src/all.rs b/src/all.rs index dc34bdf6..2fef9ae6 100644 --- a/src/all.rs +++ b/src/all.rs @@ -4,9 +4,9 @@ //! A list of all supported encodings. Useful for encodings fixed in the compile time. -use index_singlebyte as index; -use codec; -use types::EncodingRef; +use crate::index_singlebyte as index; +use crate::codec; +use crate::types::EncodingRef; macro_rules! unique( ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+, val=$val:ident) => ( @@ -81,8 +81,8 @@ unique!(var=HZ, mod=codec::simpchinese, val=HZEncoding); unique!(var=BIG5_2003, mod=codec::tradchinese, val=BigFive2003Encoding); pub mod whatwg { - use index_singlebyte as index; - use codec; + use crate::index_singlebyte as index; + use crate::codec; singlebyte!(var=X_USER_DEFINED, mod=codec::whatwg::x_user_defined, name="pua-mapped-binary", whatwg=Some("x-user-defined")); diff --git a/src/codec/ascii.rs b/src/codec/ascii.rs index 0d0465f2..a5179f51 100644 --- a/src/codec/ascii.rs +++ b/src/codec/ascii.rs @@ -6,7 +6,7 @@ use std::mem; use std::convert::Into; -use types::*; +use crate::types::*; /** * ASCII, also known as ISO/IEC 646:US. @@ -100,8 +100,8 @@ impl RawDecoder for ASCIIDecoder { mod tests { extern crate test; use super::ASCIIEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder() { diff --git a/src/codec/error.rs b/src/codec/error.rs index b7076db0..99b14cf5 100644 --- a/src/codec/error.rs +++ b/src/codec/error.rs @@ -5,7 +5,7 @@ //! A placeholder encoding that returns encoder/decoder error for every case. use std::convert::Into; -use types::*; +use crate::types::*; /// An encoding that returns encoder/decoder error for every case. #[derive(Clone, Copy)] @@ -70,7 +70,7 @@ impl RawDecoder for ErrorDecoder { #[cfg(test)] mod tests { use super::ErrorEncoding; - use types::*; + use crate::types::*; #[test] fn test_encoder() { diff --git a/src/codec/japanese.rs b/src/codec/japanese.rs index 615bb75c..29163c0f 100644 --- a/src/codec/japanese.rs +++ b/src/codec/japanese.rs @@ -6,9 +6,9 @@ use std::convert::Into; use std::default::Default; -use util::StrCharIndex; -use index_japanese as index; -use types::*; +use crate::util::StrCharIndex; +use crate::index_japanese as index; +use crate::types::*; use self::ISO2022JPState::{ASCII,Katakana,Lead}; /** @@ -116,7 +116,7 @@ stateful_decoder! { module eucjp; internal pub fn map_two_0208_bytes(lead: u8, trail: u8) -> u32 { - use index_japanese as index; + use crate::index_japanese as index; let lead = lead as u16; let trail = trail as u16; @@ -128,7 +128,7 @@ stateful_decoder! { } internal pub fn map_two_0212_bytes(lead: u8, trail: u8) -> u32 { - use index_japanese as index; + use crate::index_japanese as index; let lead = lead as u16; let trail = trail as u16; @@ -191,8 +191,8 @@ transient: mod eucjp_tests { extern crate test; use super::EUCJPEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { @@ -538,7 +538,7 @@ stateful_decoder! { module windows31j; internal pub fn map_two_0208_bytes(lead: u8, trail: u8) -> u32 { - use index_japanese as index; + use crate::index_japanese as index; let lead = lead as u16; let trail = trail as u16; @@ -578,8 +578,8 @@ transient: mod windows31j_tests { extern crate test; use super::Windows31JEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { @@ -882,7 +882,7 @@ stateful_decoder! { module iso2022jp; internal pub fn map_two_0208_bytes(lead: u8, trail: u8) -> u32 { - use index_japanese as index; + use crate::index_japanese as index; let lead = lead as u16; let trail = trail as u16; @@ -894,7 +894,7 @@ stateful_decoder! { } internal pub fn map_two_0212_bytes(lead: u8, trail: u8) -> u32 { - use index_japanese as index; + use crate::index_japanese as index; let lead = lead as u16; let trail = trail as u16; @@ -1002,8 +1002,8 @@ transient: mod iso2022jp_tests { extern crate test; use super::ISO2022JPEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { diff --git a/src/codec/korean.rs b/src/codec/korean.rs index cf879d57..8dc6f859 100644 --- a/src/codec/korean.rs +++ b/src/codec/korean.rs @@ -6,9 +6,9 @@ use std::convert::Into; use std::default::Default; -use util::StrCharIndex; -use index_korean as index; -use types::*; +use crate::util::StrCharIndex; +use crate::index_korean as index; +use crate::types::*; /** * Windows code page 949. @@ -102,7 +102,7 @@ stateful_decoder! { module windows949; internal pub fn map_two_bytes(lead: u8, trail: u8) -> u32 { - use index_korean as index; + use crate::index_korean as index; let lead = lead as u16; let trail = trail as u16; @@ -138,8 +138,8 @@ transient: mod windows949_tests { extern crate test; use super::Windows949Encoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { diff --git a/src/codec/simpchinese.rs b/src/codec/simpchinese.rs index b14580c6..54d9e715 100644 --- a/src/codec/simpchinese.rs +++ b/src/codec/simpchinese.rs @@ -6,9 +6,9 @@ use std::convert::Into; use std::default::Default; -use util::StrCharIndex; -use index_simpchinese as index; -use types::*; +use crate::util::StrCharIndex; +use crate::index_simpchinese as index; +use crate::types::*; /// GB 18030. /// @@ -188,7 +188,7 @@ stateful_decoder! { module gb18030; internal pub fn map_two_bytes(lead: u8, trail: u8) -> u32 { - use index_simpchinese as index; + use crate::index_simpchinese as index; let lead = lead as u16; let trail = trail as u16; @@ -203,7 +203,7 @@ stateful_decoder! { } internal pub fn map_four_bytes(b1: u8, b2: u8, b3: u8, b4: u8) -> u32 { - use index_simpchinese as index; + use crate::index_simpchinese as index; // no range check here, caller should have done all checks let index = (b1 as u32 - 0x81) * 12600 + (b2 as u32 - 0x30) * 1260 + @@ -250,8 +250,8 @@ transient: mod gb18030_tests { extern crate test; use super::GB18030Encoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { @@ -427,8 +427,8 @@ mod gb18030_tests { mod gbk_tests { extern crate test; use super::GBKEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; // GBK and GB 18030 share the same decoder logic. @@ -579,7 +579,7 @@ stateful_decoder! { module hz; internal pub fn map_two_bytes(lead: u8, trail: u8) -> u32 { - use index_simpchinese as index; + use crate::index_simpchinese as index; let lead = lead as u16; let trail = trail as u16; @@ -647,8 +647,8 @@ transient: mod hz_tests { extern crate test; use super::HZEncoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { diff --git a/src/codec/singlebyte.rs b/src/codec/singlebyte.rs index 0f0c2094..1e9eb961 100644 --- a/src/codec/singlebyte.rs +++ b/src/codec/singlebyte.rs @@ -5,8 +5,8 @@ //! Common codec implementation for single-byte encodings. use std::convert::Into; -use util::{as_char, StrCharIndex}; -use types::*; +use crate::util::{as_char, StrCharIndex}; +use crate::types::*; /// A common framework for single-byte encodings based on ASCII. #[derive(Copy, Clone)] @@ -118,8 +118,8 @@ pub mod iso_8859_1 { #[cfg(test)] mod tests { - use all::ISO_8859_2; - use types::*; + use crate::all::ISO_8859_2; + use crate::types::*; #[test] fn test_encoder_non_bmp() { diff --git a/src/codec/tradchinese.rs b/src/codec/tradchinese.rs index 82236ef4..98b32062 100644 --- a/src/codec/tradchinese.rs +++ b/src/codec/tradchinese.rs @@ -6,9 +6,9 @@ use std::convert::Into; use std::default::Default; -use util::StrCharIndex; -use index_tradchinese as index; -use types::*; +use crate::util::StrCharIndex; +use crate::index_tradchinese as index; +use crate::types::*; /** * Big5-2003 with common extensions. (XXX with asymmetric HKSCS-2008 support) @@ -107,7 +107,7 @@ stateful_decoder! { module bigfive2003; internal pub fn map_two_bytes(lead: u8, trail: u8) -> u32 { - use index_tradchinese as index; + use crate::index_tradchinese as index; let lead = lead as u16; let trail = trail as u16; @@ -150,8 +150,8 @@ transient: mod bigfive2003_tests { extern crate test; use super::BigFive2003Encoding; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_encoder_valid() { diff --git a/src/codec/utf_16.rs b/src/codec/utf_16.rs index 1b250bf5..4f64cb9a 100644 --- a/src/codec/utf_16.rs +++ b/src/codec/utf_16.rs @@ -5,8 +5,8 @@ //! UTF-16. use std::convert::Into; -use util::as_char; -use types::*; +use crate::util::as_char; +use crate::types::*; /// UTF-16 (UCS Transformation Format, 16-bit), in little endian. /// @@ -307,7 +307,7 @@ mod tests { // since big endian is easier to inspect we test UTF16BEEncoding only. use super::UTF16BEEncoding; - use types::*; + use crate::types::*; #[test] fn test_encoder_valid() { diff --git a/src/codec/utf_8.rs b/src/codec/utf_8.rs index a0f4bd88..d0a53d25 100644 --- a/src/codec/utf_8.rs +++ b/src/codec/utf_8.rs @@ -26,7 +26,7 @@ use std::{str, mem}; use std::convert::Into; -use types::*; +use crate::types::*; /** * UTF-8 (UCS Transformation Format, 8-bit). @@ -244,8 +244,8 @@ mod tests { use super::{UTF8Encoding, from_utf8}; use std::str; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[test] fn test_valid() { @@ -632,8 +632,8 @@ mod tests { extern crate test; use super::super::{UTF8Encoding, from_utf8}; use std::str; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[bench] fn bench_encode(bencher: &mut test::Bencher) { @@ -687,8 +687,8 @@ mod tests { extern crate test; use super::super::{UTF8Encoding, from_utf8}; use std::str; - use testutils; - use types::*; + use crate::testutils; + use crate::types::*; #[bench] fn bench_encode(bencher: &mut test::Bencher) { @@ -740,9 +740,9 @@ mod tests { extern crate test; use super::super::{UTF8Encoding, from_utf8}; use std::str; - use testutils; - use types::*; - use types::DecoderTrap::Replace as DecodeReplace; + use crate::testutils; + use crate::types::*; + use crate::types::DecoderTrap::Replace as DecodeReplace; #[bench] fn bench_decode_replace(bencher: &mut test::Bencher) { @@ -785,9 +785,9 @@ mod tests { extern crate test; use super::super::{UTF8Encoding, from_utf8}; use std::str; - use testutils; - use types::*; - use types::DecoderTrap::Replace as DecodeReplace; + use crate::testutils; + use crate::types::*; + use crate::types::DecoderTrap::Replace as DecodeReplace; #[bench] fn bench_decode_replace(bencher: &mut test::Bencher) { diff --git a/src/codec/whatwg.rs b/src/codec/whatwg.rs index e58e4051..610ecf6e 100644 --- a/src/codec/whatwg.rs +++ b/src/codec/whatwg.rs @@ -4,8 +4,8 @@ //! Asymmetric or special encoding constructions required by the WHATWG Encoding standard. -use codec; -use types::*; +use crate::codec; +use crate::types::*; /// Replacement encoding used to solve a particular attack vector due to mismatching server and /// client supports for encodings. It is rarely useful outside. diff --git a/src/label.rs b/src/label.rs index c9762e10..63e243b0 100644 --- a/src/label.rs +++ b/src/label.rs @@ -4,8 +4,8 @@ //! An interface for retrieving an encoding (or a set of encodings) from a string/numeric label. -use all; -use types::EncodingRef; +use crate::all; +use crate::types::EncodingRef; /// Returns an encoding from given label, defined in the WHATWG Encoding standard, if any. /// Implements "get an encoding" algorithm: http://encoding.spec.whatwg.org/#concept-encoding-get @@ -324,7 +324,7 @@ pub fn encoding_from_windows_code_page(cp: usize) -> Option { #[cfg(test)] mod tests { extern crate test; - use all; + use crate::all; use super::encoding_from_whatwg_label; #[test] diff --git a/src/lib.rs b/src/lib.rs index f6b1f272..9ae9d87f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -267,7 +267,7 @@ pub mod label; /// Return the result and the used encoding. pub fn decode(input: &[u8], trap: DecoderTrap, fallback_encoding: EncodingRef) -> (Result>, EncodingRef) { - use all::{UTF_8, UTF_16LE, UTF_16BE}; + use crate::all::{UTF_8, UTF_16LE, UTF_16BE}; if input.starts_with(&[0xEF, 0xBB, 0xBF]) { (UTF_8.decode(&input[3..], trap), UTF_8 as EncodingRef) } else if input.starts_with(&[0xFE, 0xFF]) { diff --git a/src/testutils.rs b/src/testutils.rs index 7bc1338d..0d1eb8df 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -5,7 +5,7 @@ //! Macros and utilities for testing. use std::borrow::ToOwned; -use types::{RawDecoder, RawEncoder}; +use crate::types::{RawDecoder, RawEncoder}; pub struct TestResult<'a, Output: 'a + ?Sized + ToOwned> { pub expected_return: (usize, Option), @@ -152,7 +152,7 @@ impl Testable for dyn RawEncoder { macro_rules! assert_expected { ($result:expr, $func:expr, $filter:expr) => ({ - use testutils::Testable; + use crate::testutils::Testable; match $result { result => { assert!(result.expected_return == result.actual_return, diff --git a/src/types.rs b/src/types.rs index a837ab1a..89cbf024 100644 --- a/src/types.rs +++ b/src/types.rs @@ -10,7 +10,7 @@ pub use super::decode; mod tests { use super::*; use super::EncoderTrap::NcrEscape; - use util::StrCharIndex; + use crate::util::StrCharIndex; use std::convert::Into; use std::sync::mpsc::channel; diff --git a/src/util.rs b/src/util.rs index 8ac9d077..798a59d0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,7 +8,7 @@ use std::{str, char, mem}; use std::marker::PhantomData; use std::convert::Into; use std::default::Default; -use types; +use crate::types; /// Unchecked conversion to `char`. pub fn as_char(ch: u32) -> char { @@ -170,7 +170,7 @@ macro_rules! stateful_decoder { } pub mod internal { - pub type Context<'a, Data> = ::util::StatefulDecoderHelper<'a, super::State, Data>; + pub type Context<'a, Data> = crate::util::StatefulDecoderHelper<'a, super::State, Data>; $($item)* } @@ -229,11 +229,11 @@ macro_rules! stateful_decoder { )* } - pub fn raw_feed(mut st: State, input: &[u8], output: &mut dyn (::types::StringWriter), - data: &T) -> (State, usize, Option<::types::CodecError>) { + pub fn raw_feed(mut st: State, input: &[u8], output: &mut dyn (crate::types::StringWriter), + data: &T) -> (State, usize, Option) { output.writer_hint(input.len()); - let mut ctx = ::util::StatefulDecoderHelper::new(input, output, data); + let mut ctx = crate::util::StatefulDecoderHelper::new(input, output, data); let mut processed = 0; let st_ = match st { @@ -271,10 +271,10 @@ macro_rules! stateful_decoder { (st, processed, None) } - pub fn raw_finish(mut st: State, output: &mut dyn (::types::StringWriter), - data: &T) -> (State, Option<::types::CodecError>) { + pub fn raw_finish(mut st: State, output: &mut dyn (crate::types::StringWriter), + data: &T) -> (State, Option) { #![allow(unused_mut, unused_variables)] - let mut ctx = ::util::StatefulDecoderHelper::new(&[], output, data); + let mut ctx = crate::util::StatefulDecoderHelper::new(&[], output, data); let st = match ::std::mem::replace(&mut st, $inist) { $inist => { let $inictx = &mut ctx; $($inifin);+ }, $( From e2215e7d5af6bee618d660475cb69947d542f65d Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:49:14 -0500 Subject: [PATCH 3/9] cd types && cargo +nightly fix --- src/types/examples/rot13.rs | 26 +++++++++++++------------- src/types/lib.rs | 34 +++++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/types/examples/rot13.rs b/src/types/examples/rot13.rs index 2bf03779..0afbf2d9 100644 --- a/src/types/examples/rot13.rs +++ b/src/types/examples/rot13.rs @@ -20,26 +20,26 @@ pub struct ROT13Encoding; impl Encoding for ROT13Encoding { fn name(&self) -> &'static str { "rot13" } fn whatwg_name(&self) -> Option<&'static str> { None } - fn raw_encoder(&self) -> Box { ROT13Encoder::new() } - fn raw_decoder(&self) -> Box { ROT13Decoder::new() } + fn raw_encoder(&self) -> Box { ROT13Encoder::new() } + fn raw_decoder(&self) -> Box { ROT13Decoder::new() } } #[derive(Clone, Copy)] pub struct ROT13Encoder; impl ROT13Encoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(ROT13Encoder) } } impl RawEncoder for ROT13Encoder { - fn from_self(&self) -> Box { + fn from_self(&self) -> Box { ROT13Encoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option) { output.writer_hint(input.len()); for byte in input.bytes() { output.write_byte(rotate_byte(byte)) @@ -47,7 +47,7 @@ impl RawEncoder for ROT13Encoder { (input.len(), None) } - fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option { None } } @@ -57,18 +57,18 @@ impl RawEncoder for ROT13Encoder { pub struct ROT13Decoder; impl ROT13Decoder { - pub fn new() -> Box { + pub fn new() -> Box { Box::new(ROT13Decoder) } } impl RawDecoder for ROT13Decoder { - fn from_self(&self) -> Box { + fn from_self(&self) -> Box { ROT13Decoder::new() } fn is_ascii_compatible(&self) -> bool { true } - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option) { + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option) { output.writer_hint(input.len()); let string = match from_utf8(input) { Ok(s) => s, @@ -80,22 +80,22 @@ impl RawDecoder for ROT13Decoder { }; for ch in string.chars() { match ch { - 'a'...'z' | 'A'...'Z' => { output.write_char(rotate_byte(ch as u8) as char) }, + 'a'..='z' | 'A'..='Z' => { output.write_char(rotate_byte(ch as u8) as char) }, _ => { output.write_char(ch) } } } (input.len(), None) } - fn raw_finish(&mut self, _output: &mut StringWriter) -> Option { + fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option { None } } fn rotate_byte(byte: u8) -> u8 { match byte { - b'a'...b'm' | b'A'...b'M' => { byte + 13 } - b'n'...b'z' | b'N'...b'Z' => { byte - 13 } + b'a'..=b'm' | b'A'..=b'M' => { byte + 13 } + b'n'..=b'z' | b'N'..=b'Z' => { byte - 13 } _ => { byte } } } diff --git a/src/types/lib.rs b/src/types/lib.rs index 435410b4..aa2f36d7 100644 --- a/src/types/lib.rs +++ b/src/types/lib.rs @@ -134,7 +134,7 @@ impl StringWriter for String { /// This is a lower level interface, and normally `Encoding::encode` should be used instead. pub trait RawEncoder: Send + 'static { /// Creates a fresh `RawEncoder` instance which parameters are same as `self`. - fn from_self(&self) -> Box; + fn from_self(&self) -> Box; /// Returns true if this encoding is compatible to ASCII, /// i.e. U+0000 through U+007F always map to bytes 00 through 7F and nothing else. @@ -145,20 +145,20 @@ pub trait RawEncoder: Send + 'static { /// and returns a byte offset to the first unprocessed character /// (that can be zero when the first such character appeared in the prior calls to `raw_feed`) /// and optional error information (None means success). - fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option); + fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option); /// Finishes the encoder, /// pushes the an encoded byte sequence at the end of the given output, /// and returns optional error information (None means success). /// `remaining` value of the error information, if any, is always an empty string. - fn raw_finish(&mut self, output: &mut ByteWriter) -> Option; + fn raw_finish(&mut self, output: &mut dyn ByteWriter) -> Option; } /// Decoder converting a byte sequence into a Unicode string. /// This is a lower level interface, and normally `Encoding::decode` should be used instead. pub trait RawDecoder: Send + 'static { /// Creates a fresh `RawDecoder` instance which parameters are same as `self`. - fn from_self(&self) -> Box; + fn from_self(&self) -> Box; /// Returns true if this encoding is compatible to ASCII, /// i.e. bytes 00 through 7F always map to U+0000 through U+007F and nothing else. @@ -169,17 +169,17 @@ pub trait RawDecoder: Send + 'static { /// and returns an offset to the first unprocessed byte /// (that can be zero when the first such byte appeared in the prior calls to `raw_feed`) /// and optional error information (None means success). - fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option); + fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option); /// Finishes the decoder, /// pushes the a decoded string at the end of the given output, /// and returns optional error information (None means success). - fn raw_finish(&mut self, output: &mut StringWriter) -> Option; + fn raw_finish(&mut self, output: &mut dyn StringWriter) -> Option; } /// A trait object using dynamic dispatch which is a sendable reference to the encoding, /// for code where the encoding is not known at compile-time. -pub type EncodingRef = &'static (Encoding + Send + Sync); +pub type EncodingRef = &'static (dyn Encoding + Send + Sync); /// Character encoding. pub trait Encoding { @@ -193,10 +193,10 @@ pub trait Encoding { fn whatwg_name(&self) -> Option<&'static str> { None } /// Creates a new encoder. - fn raw_encoder(&self) -> Box; + fn raw_encoder(&self) -> Box; /// Creates a new decoder. - fn raw_decoder(&self) -> Box; + fn raw_decoder(&self) -> Box; /// An easy-to-use interface to `RawEncoder`. /// On the encoder error `trap` is called, @@ -208,7 +208,7 @@ pub trait Encoding { } /// Encode into a `ByteWriter`. - fn encode_to(&self, input: &str, trap: EncoderTrap, ret: &mut ByteWriter) + fn encode_to(&self, input: &str, trap: EncoderTrap, ret: &mut dyn ByteWriter) -> Result<(), Cow<'static, str>> { // we don't need to keep `unprocessed` here; @@ -256,7 +256,7 @@ pub trait Encoding { /// /// This does *not* handle partial characters at the beginning or end of `input`! /// Use `RawDecoder` for incremental decoding. - fn decode_to(&self, input: &[u8], trap: DecoderTrap, ret: &mut StringWriter) + fn decode_to(&self, input: &[u8], trap: DecoderTrap, ret: &mut dyn StringWriter) -> Result<(), Cow<'static, str>> { // we don't need to keep `unprocessed` here; @@ -292,7 +292,7 @@ pub trait Encoding { } } -impl<'a> fmt::Debug for &'a Encoding { +impl<'a> fmt::Debug for &'a dyn Encoding { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { try!(fmt.write_str("Encoding(")); try!(fmt.write_str(self.name())); @@ -303,11 +303,11 @@ impl<'a> fmt::Debug for &'a Encoding { /// A type of the bare function in `EncoderTrap` values. pub type EncoderTrapFunc = - extern "Rust" fn(encoder: &mut RawEncoder, input: &str, output: &mut ByteWriter) -> bool; + extern "Rust" fn(encoder: &mut dyn RawEncoder, input: &str, output: &mut dyn ByteWriter) -> bool; /// A type of the bare function in `DecoderTrap` values. pub type DecoderTrapFunc = - extern "Rust" fn(decoder: &mut RawDecoder, input: &[u8], output: &mut StringWriter) -> bool; + extern "Rust" fn(decoder: &mut dyn RawDecoder, input: &[u8], output: &mut dyn StringWriter) -> bool; /// Trap, which handles decoder errors. #[derive(Copy)] @@ -329,7 +329,7 @@ pub enum DecoderTrap { impl DecoderTrap { /// Handles a decoder error. May write to the output writer. /// Returns true only when it is fine to keep going. - pub fn trap(&self, decoder: &mut RawDecoder, input: &[u8], output: &mut StringWriter) -> bool { + pub fn trap(&self, decoder: &mut dyn RawDecoder, input: &[u8], output: &mut dyn StringWriter) -> bool { match *self { DecoderTrap::Strict => false, DecoderTrap::Replace => { output.write_char('\u{fffd}'); true }, @@ -374,8 +374,8 @@ pub enum EncoderTrap { impl EncoderTrap { /// Handles an encoder error. May write to the output writer. /// Returns true only when it is fine to keep going. - pub fn trap(&self, encoder: &mut RawEncoder, input: &str, output: &mut ByteWriter) -> bool { - fn reencode(encoder: &mut RawEncoder, input: &str, output: &mut ByteWriter, + pub fn trap(&self, encoder: &mut dyn RawEncoder, input: &str, output: &mut dyn ByteWriter) -> bool { + fn reencode(encoder: &mut dyn RawEncoder, input: &str, output: &mut dyn ByteWriter, trapname: &str) -> bool { if encoder.is_ascii_compatible() { // optimization! output.write_bytes(input.as_bytes()); From 4136d98c27b5ee0efaa5918092931a203c6059ce Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:49:37 -0500 Subject: [PATCH 4/9] cd types && cargo +nightly fix --edition --- src/types/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/lib.rs b/src/types/lib.rs index aa2f36d7..90201d15 100644 --- a/src/types/lib.rs +++ b/src/types/lib.rs @@ -294,9 +294,9 @@ pub trait Encoding { impl<'a> fmt::Debug for &'a dyn Encoding { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(fmt.write_str("Encoding(")); - try!(fmt.write_str(self.name())); - try!(fmt.write_str(")")); + r#try!(fmt.write_str("Encoding(")); + r#try!(fmt.write_str(self.name())); + r#try!(fmt.write_str(")")); Ok(()) } } From 1095cdb8176565916459babd1ea9b958b90aa28d Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:50:17 -0500 Subject: [PATCH 5/9] cd index/japanese && cargon +nightly fix --- src/index/japanese/jis0208.rs | 16 ++++++++-------- src/index/japanese/jis0212.rs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/index/japanese/jis0208.rs b/src/index/japanese/jis0208.rs index ede53978..73df0a85 100644 --- a/src/index/japanese/jis0208.rs +++ b/src/index/japanese/jis0208.rs @@ -13,14 +13,14 @@ fn premap_forward(code: u16) -> u16 { match code { - 0...689 => code, - 690...1127 => X, - 1128...1219 => code - 438, - 1220...1409 => X, - 1410...7807 => code - 628, - 7808...8271 => X, - 8272...8647 => code - 1092, - 8648...10715 => X, + 0..=689 => code, + 690..=1127 => X, + 1128..=1219 => code - 438, + 1220..=1409 => X, + 1410..=7807 => code - 628, + 7808..=8271 => X, + 8272..=8647 => code - 1092, + 8648..=10715 => X, _ => code - 3160, } } diff --git a/src/index/japanese/jis0212.rs b/src/index/japanese/jis0212.rs index bfa120f5..22edfc22 100644 --- a/src/index/japanese/jis0212.rs +++ b/src/index/japanese/jis0212.rs @@ -13,10 +13,10 @@ fn premap_forward(code: u16) -> u16 { match code { - 0...174 => code, - 175...533 => X, - 534...1026 => code - 359, - 1027...1409 => X, + 0..=174 => code, + 175..=533 => X, + 534..=1026 => code - 359, + 1027..=1409 => X, _ => code - 742, } } From 91d75fd44f00f4b5aae254a0d54ef297d45d8f4c Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:50:42 -0500 Subject: [PATCH 6/9] cd index/korean && cargo +nightly fix --- src/index/korean/euc_kr.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index/korean/euc_kr.rs b/src/index/korean/euc_kr.rs index b9f5fe0f..6466be4b 100644 --- a/src/index/korean/euc_kr.rs +++ b/src/index/korean/euc_kr.rs @@ -16,20 +16,20 @@ fn premap_forward(code: u16) -> u16 { let c = code % 190; if c >= 96 { let dr = match r { - 0...43 => 0, - 44...46 => return X, - 47...71 => 3, + 0..=43 => 0, + 44..=46 => return X, + 47..=71 => 3, 72 => return X, - 73...124 => 4, + 73..=124 => 4, _ => return X, }; (r - dr) * (190 - 96) + (c - 96) } else { let dc = match c { - 0...25 => 0, - 26...31 => return X, - 32...57 => 6, - 58...63 => return X, + 0..=25 => 0, + 26..=31 => return X, + 32..=57 => 6, + 58..=63 => return X, _ => 12, }; (125 - 4) * (190 - 96) + r * (96 - 12) + (c - dc) From 000a97a47ebb25cd9f06472d947125a094f0157f Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:52:09 -0500 Subject: [PATCH 7/9] cd index/tradchinese && cargo +nightly fix --- src/index/tradchinese/big5.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index/tradchinese/big5.rs b/src/index/tradchinese/big5.rs index a3b41301..e6ba85ff 100644 --- a/src/index/tradchinese/big5.rs +++ b/src/index/tradchinese/big5.rs @@ -4453,7 +4453,7 @@ pub fn backward(code: u32) -> u16 { #[cfg(test)] multi_byte_tests! { dups = [ - 0...5023, 5206, 5207, 5208, 5209, 5214, 5247, 5248, 5249, 5250, 5287, + 0..=5023, 5206, 5207, 5208, 5209, 5214, 5247, 5248, 5249, 5250, 5287, 5289, 6410, 6422, 6543, 6732, 7300, 7410, 7915, 8240, 8281, 8870, 9081, 9103, 9741, 9802, 9810, 9840, 9909, 10024, 10696, 10825, 10950, 10957, 11332, 11345, 11458, 11479, 12065, 12497, 12739, 13142, 14159, 14187, From 7e034524f1b07796acb565444734534201a75d09 Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:53:34 -0500 Subject: [PATCH 8/9] Remove redundant arm of match. Compiler understands that scalars can be exhaustive --- src/codec/utf_16.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/codec/utf_16.rs b/src/codec/utf_16.rs index 4f64cb9a..a4a3d5de 100644 --- a/src/codec/utf_16.rs +++ b/src/codec/utf_16.rs @@ -67,7 +67,6 @@ impl UTF16Encoder { write_two_bytes(output, (0xdc | ((ch >> 8) & 0x3)) as u8, (ch & 0xff) as u8); } - _ => unreachable!() // XXX Rust issue #12483, this is redundant } } (input.len(), None) From 889e700ed1347dc468fad88a72bc9059a2493cea Mon Sep 17 00:00:00 2001 From: John Parton Date: Wed, 12 Aug 2020 09:54:16 -0500 Subject: [PATCH 9/9] Use ? operator instead of try! macro --- src/types/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/lib.rs b/src/types/lib.rs index 90201d15..ce799ccc 100644 --- a/src/types/lib.rs +++ b/src/types/lib.rs @@ -294,9 +294,9 @@ pub trait Encoding { impl<'a> fmt::Debug for &'a dyn Encoding { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - r#try!(fmt.write_str("Encoding(")); - r#try!(fmt.write_str(self.name())); - r#try!(fmt.write_str(")")); + fmt.write_str("Encoding(")?; + fmt.write_str(self.name())?; + fmt.write_str(")")?; Ok(()) } }