Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/warnings #124

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions examples/recode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ fn main() {
};

let mut input = match matches.free.first().map(|s| &s[..]) {
Some("-") | None => Box::new(io::stdin()) as Box<Read>,
Some("-") | None => Box::new(io::stdin()) as Box<dyn Read>,
Some(f) => match File::open(&Path::new(f)) {
Ok(f) => Box::new(f) as Box<Read>,
Ok(f) => Box::new(f) as Box<dyn Read>,
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<Write>,
Some("-") | None => Box::new(io::stdout()) as Box<dyn Write>,
Some(f) => match File::create(&Path::new(f)) {
Ok(f) => Box::new(f) as Box<Write>,
Ok(f) => Box::new(f) as Box<dyn Write>,
Err(e) => panic!("cannot open the output {}: {}", f, e),
},
};
Expand Down
10 changes: 5 additions & 5 deletions src/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand Down Expand Up @@ -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"));
Expand Down
28 changes: 14 additions & 14 deletions src/codec/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::mem;
use std::convert::Into;
use types::*;
use crate::types::*;

/**
* ASCII, also known as ISO/IEC 646:US.
Expand All @@ -19,23 +19,23 @@ pub struct ASCIIEncoding;

impl Encoding for ASCIIEncoding {
fn name(&self) -> &'static str { "ascii" }
fn raw_encoder(&self) -> Box<RawEncoder> { ASCIIEncoder::new() }
fn raw_decoder(&self) -> Box<RawDecoder> { ASCIIDecoder::new() }
fn raw_encoder(&self) -> Box<dyn RawEncoder> { ASCIIEncoder::new() }
fn raw_decoder(&self) -> Box<dyn RawDecoder> { ASCIIDecoder::new() }
}

/// An encoder for ASCII.
#[derive(Clone, Copy)]
pub struct ASCIIEncoder;

impl ASCIIEncoder {
pub fn new() -> Box<RawEncoder> { Box::new(ASCIIEncoder) }
pub fn new() -> Box<dyn RawEncoder> { Box::new(ASCIIEncoder) }
}

impl RawEncoder for ASCIIEncoder {
fn from_self(&self) -> Box<RawEncoder> { ASCIIEncoder::new() }
fn from_self(&self) -> Box<dyn RawEncoder> { ASCIIEncoder::new() }
fn is_ascii_compatible(&self) -> bool { true }

fn raw_feed(&mut self, input: &str, output: &mut ByteWriter) -> (usize, Option<CodecError>) {
fn raw_feed(&mut self, input: &str, output: &mut dyn ByteWriter) -> (usize, Option<CodecError>) {
output.writer_hint(input.len());

match input.as_bytes().iter().position(|&ch| ch >= 0x80) {
Expand All @@ -53,7 +53,7 @@ impl RawEncoder for ASCIIEncoder {
}
}

fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option<CodecError> {
fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option<CodecError> {
None
}
}
Expand All @@ -63,17 +63,17 @@ impl RawEncoder for ASCIIEncoder {
pub struct ASCIIDecoder;

impl ASCIIDecoder {
pub fn new() -> Box<RawDecoder> { Box::new(ASCIIDecoder) }
pub fn new() -> Box<dyn RawDecoder> { Box::new(ASCIIDecoder) }
}

impl RawDecoder for ASCIIDecoder {
fn from_self(&self) -> Box<RawDecoder> { ASCIIDecoder::new() }
fn from_self(&self) -> Box<dyn RawDecoder> { ASCIIDecoder::new() }
fn is_ascii_compatible(&self) -> bool { true }

fn raw_feed(&mut self, input: &[u8], output: &mut StringWriter) -> (usize, Option<CodecError>) {
fn raw_feed(&mut self, input: &[u8], output: &mut dyn StringWriter) -> (usize, Option<CodecError>) {
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)});
}

Expand All @@ -91,7 +91,7 @@ impl RawDecoder for ASCIIDecoder {
}
}

fn raw_finish(&mut self, _output: &mut StringWriter) -> Option<CodecError> {
fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option<CodecError> {
None
}
}
Expand All @@ -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() {
Expand Down
24 changes: 12 additions & 12 deletions src/codec/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
//! 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)]
pub struct ErrorEncoding;

impl Encoding for ErrorEncoding {
fn name(&self) -> &'static str { "error" }
fn raw_encoder(&self) -> Box<RawEncoder> { ErrorEncoder::new() }
fn raw_decoder(&self) -> Box<RawDecoder> { ErrorDecoder::new() }
fn raw_encoder(&self) -> Box<dyn RawEncoder> { ErrorEncoder::new() }
fn raw_decoder(&self) -> Box<dyn RawDecoder> { ErrorDecoder::new() }
}

/// An encoder that always returns error.
#[derive(Clone, Copy)]
pub struct ErrorEncoder;

impl ErrorEncoder {
pub fn new() -> Box<RawEncoder> { Box::new(ErrorEncoder) }
pub fn new() -> Box<dyn RawEncoder> { Box::new(ErrorEncoder) }
}

impl RawEncoder for ErrorEncoder {
fn from_self(&self) -> Box<RawEncoder> { ErrorEncoder::new() }
fn from_self(&self) -> Box<dyn RawEncoder> { ErrorEncoder::new() }

fn raw_feed(&mut self, input: &str, _output: &mut ByteWriter) -> (usize, Option<CodecError>) {
fn raw_feed(&mut self, input: &str, _output: &mut dyn ByteWriter) -> (usize, Option<CodecError>) {
if let Some(ch) = input.chars().next() {
(0, Some(CodecError { upto: ch.len_utf8() as isize,
cause: "unrepresentable character".into() }))
Expand All @@ -37,7 +37,7 @@ impl RawEncoder for ErrorEncoder {
}
}

fn raw_finish(&mut self, _output: &mut ByteWriter) -> Option<CodecError> {
fn raw_finish(&mut self, _output: &mut dyn ByteWriter) -> Option<CodecError> {
None
}
}
Expand All @@ -47,30 +47,30 @@ impl RawEncoder for ErrorEncoder {
pub struct ErrorDecoder;

impl ErrorDecoder {
pub fn new() -> Box<RawDecoder> { Box::new(ErrorDecoder) }
pub fn new() -> Box<dyn RawDecoder> { Box::new(ErrorDecoder) }
}

impl RawDecoder for ErrorDecoder {
fn from_self(&self) -> Box<RawDecoder> { ErrorDecoder::new() }
fn from_self(&self) -> Box<dyn RawDecoder> { ErrorDecoder::new() }

fn raw_feed(&mut self,
input: &[u8], _output: &mut StringWriter) -> (usize, Option<CodecError>) {
input: &[u8], _output: &mut dyn StringWriter) -> (usize, Option<CodecError>) {
if input.len() > 0 {
(0, Some(CodecError { upto: 1, cause: "invalid sequence".into() }))
} else {
(0, None)
}
}

fn raw_finish(&mut self, _output: &mut StringWriter) -> Option<CodecError> {
fn raw_finish(&mut self, _output: &mut dyn StringWriter) -> Option<CodecError> {
None
}
}

#[cfg(test)]
mod tests {
use super::ErrorEncoding;
use types::*;
use crate::types::*;

#[test]
fn test_encoder() {
Expand Down
Loading