summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-10-23 20:47:08 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-10-23 20:47:08 +0100
commitd4eab4fc8d5c0cbdd0f1060638697f1198c9c472 (patch)
treee72dfe06ee03f315d2e8e7707d5c1b77d82a0102
parentc7f51c02ebeb85042e70b5cffdb58174cc8298eb (diff)
downloadparsebyregex-d4eab4fc8d5c0cbdd0f1060638697f1198c9c472.tar.bz2
Various cleanups for more modern rust
-rw-r--r--Cargo.toml4
-rw-r--r--parsebyregex-derive/Cargo.toml8
-rw-r--r--parsebyregex-derive/src/lib.rs8
-rw-r--r--parsebyregex-derive/tests/basic.rs2
-rw-r--r--parsebyregex-example/src/main.rs2
-rw-r--r--src/lib.rs5
6 files changed, 14 insertions, 15 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e1f3cc8..2f242b4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,5 +11,5 @@ members = [
]
[dependencies]
-regex = "1.1"
-lazy_static = "1.2"
+regex = "1.3"
+lazy_static = "1.4"
diff --git a/parsebyregex-derive/Cargo.toml b/parsebyregex-derive/Cargo.toml
index ea58f9f..cebfc8c 100644
--- a/parsebyregex-derive/Cargo.toml
+++ b/parsebyregex-derive/Cargo.toml
@@ -8,10 +8,10 @@ edition = "2018"
proc-macro = true
[dependencies]
-syn = {version="0.15", features=["derive","parsing","printing"]}
-quote = "0.6"
-regex = "1.1"
-proc-macro2 = "0.4"
+syn = {version="1.0", features=["derive","parsing","printing"]}
+quote = "1.0"
+regex = "1.3"
+proc-macro2 = "1.0"
[dev-dependencies]
parsebyregex = {path = ".."} \ No newline at end of file
diff --git a/parsebyregex-derive/src/lib.rs b/parsebyregex-derive/src/lib.rs
index 38381bf..80e3e23 100644
--- a/parsebyregex-derive/src/lib.rs
+++ b/parsebyregex-derive/src/lib.rs
@@ -24,7 +24,7 @@ fn impl_pbr_macro(ast: &syn::DeriveInput) -> TokenStream {
let body = gen_struct_body(&name, &regex);
quote! {
impl ParseByRegex for #name {
- fn parse_by_regex<T: AsRef<str>>(input: T) -> std::result::Result<Self, Box<std::error::Error>> {
+ fn parse_by_regex<T: AsRef<str>>(input: T) -> std::result::Result<Self, Box<dyn std::error::Error>> {
use parsebyregex::lazy_static;
use parsebyregex::Regex;
lazy_static! {
@@ -33,7 +33,7 @@ fn impl_pbr_macro(ast: &syn::DeriveInput) -> TokenStream {
if let Some(captures) = PARSER.captures(input.as_ref()) {
#body
} else {
- Err(format!("Unable to parse `{}` by `{}`", input.as_ref(), #regex))?
+ Err(format!("Unable to parse `{}` by `{}`", input.as_ref(), #regex).into())
}
}
}
@@ -49,7 +49,7 @@ fn impl_pbr_macro(ast: &syn::DeriveInput) -> TokenStream {
let body = gen_enum_body(&name, &edata);
quote! {
impl ParseByRegex for #name {
- fn parse_by_regex<T: AsRef<str>>(input: T) -> std::result::Result<Self, Box<std::error::Error>> {
+ fn parse_by_regex<T: AsRef<str>>(input: T) -> std::result::Result<Self, Box<dyn std::error::Error>> {
use parsebyregex::lazy_static;
use parsebyregex::Regex;
lazy_static! {
@@ -332,7 +332,7 @@ fn gen_enum_body(name: &syn::Ident, edata: &syn::DataEnum) -> proc_macro2::Token
quote! {
#(#parsers else)* {
- Err(format!("Unable to parse `{}` as {}", input.as_ref(), #strname))?
+ Err(format!("Unable to parse `{}` as {}", input.as_ref(), #strname).into())
}
}
}
diff --git a/parsebyregex-derive/tests/basic.rs b/parsebyregex-derive/tests/basic.rs
index 16cdefd..fab6911 100644
--- a/parsebyregex-derive/tests/basic.rs
+++ b/parsebyregex-derive/tests/basic.rs
@@ -8,7 +8,7 @@ struct Person {
pub age: u32,
}
-fn main() -> Result<(), Box<std::error::Error>> {
+fn main() -> Result<(), Box<dyn std::error::Error>> {
let person: Person = Person::parse_by_regex("age=14")?;
assert_eq!(person.age, 14);
Ok(())
diff --git a/parsebyregex-example/src/main.rs b/parsebyregex-example/src/main.rs
index 96d4d83..5defbc4 100644
--- a/parsebyregex-example/src/main.rs
+++ b/parsebyregex-example/src/main.rs
@@ -52,7 +52,7 @@ static TEST_INPUT: &str = r#"
[1518-11-05 00:55] wakes up
"#;
-fn main() -> Result<(), Box<std::error::Error>> {
+fn main() -> Result<(), Box<dyn std::error::Error>> {
let input: Result<Vec<Entry>, _> = TEST_INPUT
.trim()
.lines()
diff --git a/src/lib.rs b/src/lib.rs
index 39f26ca..abbb2fd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -14,7 +14,7 @@ pub use regex::Regex;
/// If this is implemented then you can parse things by regular expression
/// just like `FromStr`.
pub trait ParseByRegex: Sized {
- fn parse_by_regex<T: AsRef<str>>(input: T) -> Result<Self, Box<Error>>;
+ fn parse_by_regex<T: AsRef<str>>(input: T) -> Result<Self, Box<dyn Error>>;
}
impl<TY> ParseByRegex for TY
@@ -22,7 +22,7 @@ where
TY: FromStr,
<TY as FromStr>::Err: Error + 'static,
{
- fn parse_by_regex<T: AsRef<str>>(input: T) -> Result<Self, Box<Error>> {
+ fn parse_by_regex<T: AsRef<str>>(input: T) -> Result<Self, Box<dyn Error>> {
Ok(<Self as FromStr>::from_str(input.as_ref())?)
}
}
@@ -36,5 +36,4 @@ mod tests {
assert!(f.is_ok());
assert_eq!(f.unwrap(), 1);
}
-
}