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

Remove deprecation warnings for rustc 1.41 #153

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Error for EmitError {
}
}

fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
None
}
}
Expand All @@ -38,7 +38,7 @@ impl From<fmt::Error> for EmitError {
}

pub struct YamlEmitter<'a> {
writer: &'a mut fmt::Write,
writer: &'a mut dyn fmt::Write,
best_indent: usize,
compact: bool,

Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})
|| [
Expand Down Expand Up @@ -638,5 +638,4 @@ a:

assert_eq!(s, writer);
}

}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,4 @@ key1:a2
assert!(YamlLoader::load_from_str(s).is_err());
assert!(try_fail(s).is_err());
}

}
10 changes: 5 additions & 5 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Error for ScanError {
self.info.as_ref()
}

fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
None
}
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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!(),
}
}
Expand Down
15 changes: 10 additions & 5 deletions tests/test_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ fn test_colon_in_string() {
#[test]
fn test_numberlike_strings() {
let docs = [
r#"x: "1234""#, r#"x: "01234""#, r#""1234""#,
r#""01234""#, r#"" 01234""#, r#""0x1234""#,
r#"x: "1234""#,
r#"x: "01234""#,
r#""1234""#,
r#""01234""#,
r#"" 01234""#,
r#""0x1234""#,
r#"" 0x1234""#,
];

Expand All @@ -53,13 +57,14 @@ fn test_numberlike_strings() {
/// Example from https://github.com/chyh1990/yaml-rust/issues/133
#[test]
fn test_issue133() {

let doc = YamlLoader::load_from_str("\"0x123\"").unwrap().pop().unwrap();
let doc = YamlLoader::load_from_str("\"0x123\"")
.unwrap()
.pop()
.unwrap();
assert_eq!(doc, Yaml::String("0x123".to_string()));

let mut out_str = String::new();
YamlEmitter::new(&mut out_str).dump(&doc).unwrap();
let doc2 = YamlLoader::load_from_str(&out_str).unwrap().pop().unwrap();
assert_eq!(doc, doc2); // This failed because the type has changed to a number now

}