From 95562ac8492cf715f53a76014e72b290249a0f0c Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 27 May 2020 14:15:28 +0800 Subject: [PATCH 1/3] Rust 2018 transition --- parser/src/emitter.rs | 18 +++++++++--------- parser/src/lib.rs | 8 ++++---- parser/src/parser.rs | 2 +- parser/src/scanner.rs | 10 +++++----- parser/src/yaml.rs | 6 +++--- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/parser/src/emitter.rs b/parser/src/emitter.rs index 872d1c8..d461001 100644 --- a/parser/src/emitter.rs +++ b/parser/src/emitter.rs @@ -1,7 +1,7 @@ use std::convert::From; use std::error::Error; use std::fmt::{self, Display}; -use yaml::{Hash, Yaml}; +use crate::yaml::{Hash, Yaml}; #[derive(Copy, Clone, Debug)] pub enum EmitError { @@ -17,7 +17,7 @@ impl Error for EmitError { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { None } } @@ -38,7 +38,7 @@ impl From for EmitError { } pub struct YamlEmitter<'a> { - writer: &'a mut fmt::Write, + writer: &'a mut dyn fmt::Write, best_indent: usize, compact: bool, @@ -48,7 +48,7 @@ pub struct YamlEmitter<'a> { pub type EmitResult = Result<(), EmitError>; // from serialize::json -fn escape_str(wr: &mut fmt::Write, v: &str) -> Result<(), fmt::Error> { +fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> Result<(), fmt::Error> { wr.write_str("\"")?; let mut start = 0; @@ -111,7 +111,7 @@ fn escape_str(wr: &mut fmt::Write, v: &str) -> Result<(), fmt::Error> { } impl<'a> YamlEmitter<'a> { - pub fn new(writer: &'a mut fmt::Write) -> YamlEmitter { + pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter { YamlEmitter { writer, best_indent: 2, @@ -316,12 +316,12 @@ fn need_quotes(string: &str) -> bool { | '\"' | '\'' | '\\' - | '\0'...'\x06' + | '\0'..='\x06' | '\t' | '\n' | '\r' - | '\x0e'...'\x1a' - | '\x1c'...'\x1f' => true, + | '\x0e'..='\x1a' + | '\x1c'..='\x1f' => true, _ => false, }) || [ @@ -344,7 +344,7 @@ fn need_quotes(string: &str) -> bool { #[cfg(test)] mod test { use super::*; - use YamlLoader; + use crate::YamlLoader; #[test] fn test_emit_simple() { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 40cff18..af1423c 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -52,10 +52,10 @@ pub mod scanner; pub mod yaml; // reexport key APIs -pub use emitter::{EmitError, YamlEmitter}; -pub use parser::Event; -pub use scanner::ScanError; -pub use yaml::{Yaml, YamlLoader}; +pub use crate::emitter::{EmitError, YamlEmitter}; +pub use crate::parser::Event; +pub use crate::scanner::ScanError; +pub use crate::yaml::{Yaml, YamlLoader}; #[cfg(test)] mod tests { diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 22692ff..cf25fdd 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -1,4 +1,4 @@ -use scanner::*; +use crate::scanner::*; use std::collections::HashMap; #[derive(Clone, Copy, PartialEq, Debug, Eq)] diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index 6f4fa58..b2ce148 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -67,7 +67,7 @@ impl Error for ScanError { self.info.as_ref() } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { None } } @@ -199,7 +199,7 @@ fn is_digit(c: char) -> bool { #[inline] fn is_alpha(c: char) -> bool { match c { - '0'...'9' | 'a'...'z' | 'A'...'Z' => true, + '0'..='9' | 'a'..='z' | 'A'..='Z' => true, '_' | '-' => true, _ => false, } @@ -211,9 +211,9 @@ fn is_hex(c: char) -> bool { #[inline] fn as_hex(c: char) -> u32 { match c { - '0'...'9' => (c as u32) - ('0' as u32), - 'a'...'f' => (c as u32) - ('a' as u32) + 10, - 'A'...'F' => (c as u32) - ('A' as u32) + 10, + '0'..='9' => (c as u32) - ('0' as u32), + 'a'..='f' => (c as u32) - ('a' as u32) + 10, + 'A'..='F' => (c as u32) - ('A' as u32) + 10, _ => unreachable!(), } } diff --git a/parser/src/yaml.rs b/parser/src/yaml.rs index fe112cc..f529f38 100644 --- a/parser/src/yaml.rs +++ b/parser/src/yaml.rs @@ -1,6 +1,6 @@ use linked_hash_map::LinkedHashMap; -use parser::*; -use scanner::{Marker, ScanError, TScalarStyle, TokenType}; +use crate::parser::*; +use crate::scanner::{Marker, ScanError, TScalarStyle, TokenType}; use std::collections::BTreeMap; use std::f64; use std::i64; @@ -368,7 +368,7 @@ impl Iterator for YamlIter { #[cfg(test)] mod test { use std::f64; - use yaml::*; + use crate::yaml::*; #[test] fn test_coerce() { let s = "--- From 8d26a5eca34efc078a81d3d0dc6ef519a36e291b Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 27 May 2020 14:19:22 +0800 Subject: [PATCH 2/3] Remove deprecated API --- parser/Cargo.toml | 1 + parser/src/emitter.rs | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 7bc449a..282de92 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT/Apache-2.0" description = "The missing YAML 1.2 parser for rust" repository = "https://github.com/chyh1990/yaml-rust" readme = "README.md" +edition = "2018" [dependencies] linked-hash-map = ">=0.0.9, <0.6" diff --git a/parser/src/emitter.rs b/parser/src/emitter.rs index d461001..ab589a3 100644 --- a/parser/src/emitter.rs +++ b/parser/src/emitter.rs @@ -10,13 +10,6 @@ pub enum EmitError { } impl Error for EmitError { - fn description(&self) -> &str { - match *self { - EmitError::FmtError(ref err) => err.description(), - EmitError::BadHashmapKey => "bad hashmap key", - } - } - fn cause(&self) -> Option<&dyn Error> { None } From a4b1bb6e9b630f341608d02e8fcce7d56f025286 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 27 May 2020 14:25:59 +0800 Subject: [PATCH 3/3] Update quickcheck to 0.9 --- parser/Cargo.toml | 2 +- parser/tests/quickcheck.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 282de92..aac5d4a 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -14,4 +14,4 @@ edition = "2018" linked-hash-map = ">=0.0.9, <0.6" [dev-dependencies] -quickcheck = "0.7" +quickcheck = "0.9" diff --git a/parser/tests/quickcheck.rs b/parser/tests/quickcheck.rs index c2c89bc..0efd679 100644 --- a/parser/tests/quickcheck.rs +++ b/parser/tests/quickcheck.rs @@ -3,7 +3,6 @@ extern crate yaml_rust; extern crate quickcheck; use quickcheck::TestResult; -use std::error::Error; use yaml_rust::{Yaml, YamlEmitter, YamlLoader}; quickcheck! { @@ -16,7 +15,7 @@ quickcheck! { } match YamlLoader::load_from_str(&out_str) { Ok(output) => TestResult::from_bool(output.len() == 1 && input == output[0]), - Err(err) => TestResult::error(err.description()), + Err(err) => TestResult::error(err.to_string()), } } }