From 2e7d05163f773dda34fc90ecbbda50e0cc6ad30e Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 18:48:17 +0700 Subject: [PATCH 1/8] Fix clippy warnings --- wsdl-parser-cli/src/main.rs | 2 +- xsd-parser-cli/src/main.rs | 2 +- xsd-parser/src/generator/base.rs | 4 ++-- xsd-parser/src/generator/enum_case.rs | 2 +- xsd-parser/src/parser/types.rs | 18 ++++-------------- xsd-parser/src/parser/utils.rs | 2 +- xsd-types/src/types/gyear.rs | 10 +++------- xsd-types/src/types/gyearmonth.rs | 10 +++------- 8 files changed, 16 insertions(+), 34 deletions(-) diff --git a/wsdl-parser-cli/src/main.rs b/wsdl-parser-cli/src/main.rs index da31a41e..c18ce5df 100644 --- a/wsdl-parser-cli/src/main.rs +++ b/wsdl-parser-cli/src/main.rs @@ -89,7 +89,7 @@ fn process_single_file(input_path: &Path, output_path: Option<&str>) -> anyhow:: } fn load_file(path: &Path) -> std::io::Result { - let mut file = fs::File::open(&path)?; + let mut file = fs::File::open(path)?; let mut text = String::new(); file.read_to_string(&mut text)?; Ok(text) diff --git a/xsd-parser-cli/src/main.rs b/xsd-parser-cli/src/main.rs index c60228bd..71eed56e 100644 --- a/xsd-parser-cli/src/main.rs +++ b/xsd-parser-cli/src/main.rs @@ -74,7 +74,7 @@ fn process_single_file(input_path: &Path, output_path: Option<&str>) -> anyhow:: } fn load_file(path: &Path) -> std::io::Result { - let mut file = fs::File::open(&path)?; + let mut file = fs::File::open(path)?; let mut text = String::new(); file.read_to_string(&mut text)?; Ok(text) diff --git a/xsd-parser/src/generator/base.rs b/xsd-parser/src/generator/base.rs index 89ed5f0c..efb8afb7 100644 --- a/xsd-parser/src/generator/base.rs +++ b/xsd-parser/src/generator/base.rs @@ -16,10 +16,10 @@ pub trait BaseGenerator { } fn format_type_name(&self, type_name: &str, gen: &Generator) -> Cow<'_, str> { - if let Some(t) = match_built_in_type(type_name, &*gen.xsd_ns.borrow()) { + if let Some(t) = match_built_in_type(type_name, &gen.xsd_ns.borrow()) { return t.into(); } - default_format_type(type_name, &*gen.target_ns.borrow()) + default_format_type(type_name, &gen.target_ns.borrow()) } fn format_name(&self, name: &str) -> Cow<'_, str> { diff --git a/xsd-parser/src/generator/enum_case.rs b/xsd-parser/src/generator/enum_case.rs index f56624cd..9639e1bb 100644 --- a/xsd-parser/src/generator/enum_case.rs +++ b/xsd-parser/src/generator/enum_case.rs @@ -21,7 +21,7 @@ pub trait EnumCaseGenerator { } fn get_name(&self, entity: &EnumCase, gen: &Generator) -> String { - default_format_type(entity.name.as_str(), &*gen.target_ns.borrow()) + default_format_type(entity.name.as_str(), &gen.target_ns.borrow()) .split("::") .last() .unwrap() diff --git a/xsd-parser/src/parser/types.rs b/xsd-parser/src/parser/types.rs index 583296f0..3dca8d29 100644 --- a/xsd-parser/src/parser/types.rs +++ b/xsd-parser/src/parser/types.rs @@ -116,21 +116,16 @@ impl StructField { } #[allow(clippy::upper_case_acronyms)] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub enum StructFieldSource { Attribute, Element, Base, Choice, + #[default] NA, } -impl Default for StructFieldSource { - fn default() -> Self { - StructFieldSource::NA - } -} - #[derive(Debug, Clone)] pub struct Facet { pub facet_type: FacetType, @@ -158,20 +153,15 @@ pub struct Enum { } #[allow(clippy::upper_case_acronyms)] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Default)] pub enum EnumSource { Restriction, Choice, Union, + #[default] NA, } -impl Default for EnumSource { - fn default() -> Self { - EnumSource::NA - } -} - #[derive(Debug, Clone, PartialEq)] pub enum TypeModifier { None, diff --git a/xsd-parser/src/parser/utils.rs b/xsd-parser/src/parser/utils.rs index 9c1a6bde..2b9e4ac5 100644 --- a/xsd-parser/src/parser/utils.rs +++ b/xsd-parser/src/parser/utils.rs @@ -19,7 +19,7 @@ pub fn find_child<'a, 'input>(node: &Node<'a, 'input>, tag_name: &str) -> Option .find(|e| e.is_element() && e.tag_name().name() == tag_name) } -pub fn get_documentation<'a>(node: &Node<'a, '_>) -> Option { +pub fn get_documentation(node: &Node<'_, '_>) -> Option { find_child(node, "annotation") .and_then(|node| find_child(&node, "documentation")) .and_then(|node| node.text().map(|s| s.to_string())) diff --git a/xsd-types/src/types/gyear.rs b/xsd-types/src/types/gyear.rs index 8e2d8596..908b8e26 100644 --- a/xsd-types/src/types/gyear.rs +++ b/xsd-types/src/types/gyear.rs @@ -36,13 +36,9 @@ impl FromStr for GYear { fn from_str(s: &str) -> Result { if let Some(s) = s.strip_prefix('-') { - let result = parse_str_positive(s); - if let Ok(mut gyear) = result { - gyear.value *= -1; - return Ok(gyear); - } else { - return result; - } + let mut gyear = parse_str_positive(s)?; + gyear.value *= -1; + return Ok(gyear); } parse_str_positive(s) } diff --git a/xsd-types/src/types/gyearmonth.rs b/xsd-types/src/types/gyearmonth.rs index 2af9fabe..35931c68 100644 --- a/xsd-types/src/types/gyearmonth.rs +++ b/xsd-types/src/types/gyearmonth.rs @@ -61,13 +61,9 @@ impl FromStr for GYearMonth { fn from_str(s: &str) -> Result { if let Some(s) = s.strip_prefix('-') { - let result = parse_str_positive(s); - if let Ok(mut gyearmonth) = result { - gyearmonth.year *= -1; - return Ok(gyearmonth); - } else { - return result; - } + let mut gyearmonth = parse_str_positive(s)?; + gyearmonth.year *= -1; + return Ok(gyearmonth); } parse_str_positive(s) } From 1142e7482fd4ebf1ffc10b711e2be63f29c60981 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 18:52:13 +0700 Subject: [PATCH 2/8] Remove excessive dependency version specification Only leave the first non-zero version number. --- wsdl-parser-cli/Cargo.toml | 6 +++--- wsdl-parser/Cargo.toml | 8 ++++---- xsd-macro-utils/Cargo.toml | 6 +++--- xsd-parser-cli/Cargo.toml | 4 ++-- xsd-parser/Cargo.toml | 16 ++++++++-------- xsd-types/Cargo.toml | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/wsdl-parser-cli/Cargo.toml b/wsdl-parser-cli/Cargo.toml index 635bcb09..7a701590 100644 --- a/wsdl-parser-cli/Cargo.toml +++ b/wsdl-parser-cli/Cargo.toml @@ -15,8 +15,8 @@ name = "wsdl-parser" path = "src/main.rs" [dependencies] -anyhow = "1.0.42" -clap = "2.33.3" -roxmltree = { version = "0.14.0", features = ["std"] } +anyhow = "1" +clap = "2" +roxmltree = { version = "0.14", features = ["std"] } wsdl-parser = { path = "../wsdl-parser" } xsd-parser = { path = "../xsd-parser" } diff --git a/wsdl-parser/Cargo.toml b/wsdl-parser/Cargo.toml index fa445c76..521fa5aa 100644 --- a/wsdl-parser/Cargo.toml +++ b/wsdl-parser/Cargo.toml @@ -11,10 +11,10 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] -Inflector = "0.11.4" -roxmltree = "0.14.0" +Inflector = "0.11" +roxmltree = "0.14" [dev-dependencies] -syn = { version = "1.0.58", features = ["full"] } -text-diff = "0.4.0" +syn = { version = "1", features = ["full"] } +text-diff = "0.4" xsd-parser = { path = "../xsd-parser" } diff --git a/xsd-macro-utils/Cargo.toml b/xsd-macro-utils/Cargo.toml index c119a0bd..91b21e9a 100644 --- a/xsd-macro-utils/Cargo.toml +++ b/xsd-macro-utils/Cargo.toml @@ -11,9 +11,9 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] -proc-macro2 = "1.0.24" -quote = "1.0.8" -syn = "1.0.58" +proc-macro2 = "1" +quote = "1" +syn = "1" [lib] proc-macro = true diff --git a/xsd-parser-cli/Cargo.toml b/xsd-parser-cli/Cargo.toml index 6110a555..53d96d5a 100644 --- a/xsd-parser-cli/Cargo.toml +++ b/xsd-parser-cli/Cargo.toml @@ -15,6 +15,6 @@ name = "xsd-parser" path = "src/main.rs" [dependencies] -anyhow = "1.0.42" -clap = "2.33.3" +anyhow = "1" +clap = "2" xsd-parser = { path = "../xsd-parser" } diff --git a/xsd-parser/Cargo.toml b/xsd-parser/Cargo.toml index af473463..412bd411 100644 --- a/xsd-parser/Cargo.toml +++ b/xsd-parser/Cargo.toml @@ -11,15 +11,15 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] -Inflector = "0.11.4" -roxmltree = "0.14.0" +Inflector = "0.11" +roxmltree = "0.14" [dev-dependencies] -num-bigint = "0.4.2" -syn = { version = "1.0.58", features = ["full"] } -text-diff = "0.4.0" -xml-rs = "0.8.3" +num-bigint = "0.4" +syn = { version = "1", features = ["full"] } +text-diff = "0.4" +xml-rs = "0.8" xsd-macro-utils = { path = "../xsd-macro-utils" } xsd-types = { path = "../xsd-types" } -yaserde = "0.7.1" -yaserde_derive = "0.7.1" +yaserde = "0.7" +yaserde_derive = "0.7" diff --git a/xsd-types/Cargo.toml b/xsd-types/Cargo.toml index 2902367d..decf8ad9 100644 --- a/xsd-types/Cargo.toml +++ b/xsd-types/Cargo.toml @@ -11,12 +11,12 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] -bigdecimal = "0.3.0" -chrono = "0.4.19" -num-bigint = "0.4.2" -xml-rs = "0.8.3" +bigdecimal = "0.3" +chrono = "0.4" +num-bigint = "0.4" +xml-rs = "0.8" xsd-macro-utils = { path = "../xsd-macro-utils" } -yaserde = "0.7.1" +yaserde = "0.7" [dev-dependencies] -yaserde_derive = "0.7.1" +yaserde_derive = "0.7" From 0baf6078dfc21a79241e7370c6322400f1bcf5c2 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 19:24:57 +0700 Subject: [PATCH 3/8] Upgrade `clap` --- Cargo.lock | 242 +++++++++++++++++++++++++++--------- wsdl-parser-cli/Cargo.toml | 2 +- wsdl-parser-cli/src/main.rs | 55 ++++---- xsd-parser-cli/Cargo.toml | 2 +- xsd-parser-cli/src/main.rs | 52 ++++---- 5 files changed, 235 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d3b44fd..4dff6286 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,31 +22,59 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.11.0" +name = "anstream" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ - "winapi 0.3.9", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "anyhow" -version = "1.0.42" +name = "anstyle" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] -name = "atty" -version = "0.2.14" +name = "anstyle-parse" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ - "hermit-abi", - "libc", - "winapi 0.3.9", + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", ] +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" + [[package]] name = "autocfg" version = "1.0.1" @@ -55,21 +83,15 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bigdecimal" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aaf33151a6429fe9211d1b276eafdf70cdff28b071e76c0b0e1503221ea3744" +checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" dependencies = [ "num-bigint", "num-integer", "num-traits", ] -[[package]] -name = "bitflags" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da1976d75adbe5fbc88130ecd119529cf1cc6a93ae1546d8696ee66f0d21af1" - [[package]] name = "cfg-if" version = "1.0.0" @@ -91,19 +113,50 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ - "ansi_term", - "atty", - "bitflags", + "anstream", + "anstyle", + "clap_lex", "strsim", - "textwrap", - "unicode-width", - "vec_map", ] +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "getopts" version = "0.2.21" @@ -123,13 +176,10 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "kernel32-sys" @@ -200,18 +250,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.28" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -244,9 +294,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -259,6 +309,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "term" version = "0.2.14" @@ -279,15 +340,6 @@ dependencies = [ "term", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "time" version = "0.1.44" @@ -299,6 +351,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-segmentation" version = "1.8.0" @@ -318,10 +376,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] -name = "vec_map" -version = "0.8.2" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "wasi" @@ -363,13 +421,79 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "wsdl-parser" version = "0.1.0" dependencies = [ "Inflector", "roxmltree", - "syn", + "syn 1.0.74", "text-diff", "xsd-parser", ] @@ -403,7 +527,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.74", ] [[package]] @@ -413,7 +537,7 @@ dependencies = [ "Inflector", "num-bigint", "roxmltree", - "syn", + "syn 1.0.74", "text-diff", "xml-rs", "xsd-macro-utils", @@ -460,10 +584,10 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c0b0a4701f203ebaecce4971a6bb8575aa07b617bdc39ddfc6ffeff3a38530d" dependencies = [ - "heck", + "heck 0.3.3", "log", "proc-macro2", "quote", - "syn", + "syn 1.0.74", "xml-rs", ] diff --git a/wsdl-parser-cli/Cargo.toml b/wsdl-parser-cli/Cargo.toml index 7a701590..3fecd060 100644 --- a/wsdl-parser-cli/Cargo.toml +++ b/wsdl-parser-cli/Cargo.toml @@ -16,7 +16,7 @@ path = "src/main.rs" [dependencies] anyhow = "1" -clap = "2" +clap = { version = "4", features = ["derive"] } roxmltree = { version = "0.14", features = ["std"] } wsdl-parser = { path = "../wsdl-parser" } xsd-parser = { path = "../xsd-parser" } diff --git a/wsdl-parser-cli/src/main.rs b/wsdl-parser-cli/src/main.rs index c18ce5df..3c53bb54 100644 --- a/wsdl-parser-cli/src/main.rs +++ b/wsdl-parser-cli/src/main.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::Parser; use anyhow::Context; @@ -11,35 +11,32 @@ use wsdl_parser::parser::definitions::Definitions; use xsd_parser::generator::builder::GeneratorBuilder; use xsd_parser::parser::schema::parse_schema; -fn main() -> anyhow::Result<()> { - let matches = App::new("wsdl-parser") - .about("An wsdl => rust code generator written in rust") - .arg( - Arg::with_name("input") - .short("i") - .long("input") - .takes_value(true) - .help("Input .wsdl file"), - ) - .arg( - Arg::with_name("output") - .short("o") - .long("output") - .takes_value(true) - .help("Output file"), - ) - .get_matches(); +#[derive(Parser)] +#[clap(name = env!("CARGO_PKG_NAME"))] +#[clap(version = env!("CARGO_PKG_VERSION"))] +#[clap(about = env!("CARGO_PKG_DESCRIPTION"))] +struct Opt { + /// Input .wsdl file + #[clap(long, short)] + input: Option, + + /// Output file + #[clap(long, short)] + output: Option, +} - let input_path = matches.value_of("input").unwrap_or("input/wsdl"); - let input_path = Path::new(input_path); - let output_path = matches.value_of("output"); +fn main() -> anyhow::Result<()> { + let opt: Opt = Opt::parse(); - let md = fs::metadata(input_path).unwrap(); + let input_path = opt.input.unwrap_or_else(|| PathBuf::from("input/wsdl")); + let md = fs::metadata(&input_path).unwrap(); if md.is_dir() { - let output_path = Path::new(output_path.unwrap_or("output/wsdl-rs")); - process_dir(input_path, output_path)?; + let output_path = opt + .output + .unwrap_or_else(|| PathBuf::from("output/wsdl-rs")); + process_dir(&input_path, &output_path)?; } else { - process_single_file(input_path, output_path)?; + process_single_file(&input_path, opt.output.as_deref())?; } Ok(()) @@ -57,13 +54,13 @@ fn process_dir(input_path: &Path, output_path: &Path) -> anyhow::Result<()> { } else { let output_file_path = PathBuf::from(path.file_name().unwrap()).with_extension("rs"); let output_file_path = output_path.join(output_file_path); - process_single_file(&path, output_file_path.to_str())?; + process_single_file(&path, Some(&output_file_path))?; } } Ok(()) } -fn process_single_file(input_path: &Path, output_path: Option<&str>) -> anyhow::Result<()> { +fn process_single_file(input_path: &Path, output_path: Option<&Path>) -> anyhow::Result<()> { let text = load_file(input_path)?; let doc = Document::parse(text.as_str()).context("Failed to parse input document")?; let definitions = Definitions::new(&doc.root_element()); @@ -95,7 +92,7 @@ fn load_file(path: &Path) -> std::io::Result { Ok(text) } -fn write_to_file(path: &str, text: &str) -> std::io::Result<()> { +fn write_to_file(path: &Path, text: &str) -> std::io::Result<()> { let mut file = fs::File::create(path)?; file.write_all(text.as_bytes())?; diff --git a/xsd-parser-cli/Cargo.toml b/xsd-parser-cli/Cargo.toml index 53d96d5a..22792f31 100644 --- a/xsd-parser-cli/Cargo.toml +++ b/xsd-parser-cli/Cargo.toml @@ -16,5 +16,5 @@ path = "src/main.rs" [dependencies] anyhow = "1" -clap = "2" +clap = { version = "4", features = ["derive"] } xsd-parser = { path = "../xsd-parser" } diff --git a/xsd-parser-cli/src/main.rs b/xsd-parser-cli/src/main.rs index 71eed56e..dd8f15f6 100644 --- a/xsd-parser-cli/src/main.rs +++ b/xsd-parser-cli/src/main.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::Parser; use anyhow::Context; @@ -10,34 +10,30 @@ use std::fs::OpenOptions; use xsd_parser::generator::builder::GeneratorBuilder; use xsd_parser::parser::parse; +#[derive(Parser)] +#[clap(name = env!("CARGO_PKG_NAME"))] +#[clap(version = env!("CARGO_PKG_VERSION"))] +#[clap(about = env!("CARGO_PKG_DESCRIPTION"))] +struct Opt { + /// Input .xsd file + #[clap(long, short)] + input: Option, + + /// Output file + #[clap(long, short)] + output: Option, +} + fn main() -> anyhow::Result<()> { - let matches = App::new("xsd-parser-rs") - .about("An xsd/wsdl => rust code generator written in rust") - .arg( - Arg::with_name("input") - .short("i") - .long("input") - .takes_value(true) - .help("Input .xsd file"), - ) - .arg( - Arg::with_name("output") - .short("o") - .long("output") - .takes_value(true) - .help("Output file"), - ) - .get_matches(); + let opt: Opt = Opt::parse(); - let input_path = matches.value_of("input").unwrap_or("input/xsd"); - let input_path = Path::new(input_path); - let output_path = matches.value_of("output"); - let md = fs::metadata(input_path).unwrap(); + let input_path = opt.input.unwrap_or_else(|| PathBuf::from("input/xsd")); + let md = fs::metadata(&input_path).unwrap(); if md.is_dir() { - let output_path = Path::new(output_path.unwrap_or("output/rs")); - process_dir(input_path, output_path)?; + let output_path = opt.output.unwrap_or_else(|| PathBuf::from("output/rs")); + process_dir(&input_path, &output_path)?; } else { - process_single_file(input_path, output_path)?; + process_single_file(&input_path, opt.output.as_deref())?; } Ok(()) @@ -54,13 +50,13 @@ fn process_dir(input_path: &Path, output_path: &Path) -> anyhow::Result<()> { } else { let output_file_path = PathBuf::from(path.file_name().unwrap()).with_extension("rs"); let output_file_path = output_path.join(output_file_path); - process_single_file(&path, output_file_path.to_str())?; + process_single_file(&path, Some(&output_file_path))?; } } Ok(()) } -fn process_single_file(input_path: &Path, output_path: Option<&str>) -> anyhow::Result<()> { +fn process_single_file(input_path: &Path, output_path: Option<&Path>) -> anyhow::Result<()> { let text = load_file(input_path)?; let rs_file = parse(text.as_str()).map_err(|_| anyhow::anyhow!("Error parsing file"))?; let gen = GeneratorBuilder::default().build(); @@ -80,7 +76,7 @@ fn load_file(path: &Path) -> std::io::Result { Ok(text) } -fn write_to_file(path: &str, text: &str) -> std::io::Result<()> { +fn write_to_file(path: &Path, text: &str) -> std::io::Result<()> { let mut file = OpenOptions::new() .write(true) .truncate(true) From 95ebc83de1c31229ec0fd2e6daeb783e82c0cfbe Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 19:25:50 +0700 Subject: [PATCH 4/8] Upgrade `syn` --- Cargo.lock | 6 +++--- wsdl-parser/Cargo.toml | 2 +- xsd-macro-utils/Cargo.toml | 2 +- xsd-parser/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4dff6286..37299caf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,7 +493,7 @@ version = "0.1.0" dependencies = [ "Inflector", "roxmltree", - "syn 1.0.74", + "syn 2.0.37", "text-diff", "xsd-parser", ] @@ -527,7 +527,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 1.0.74", + "syn 2.0.37", ] [[package]] @@ -537,7 +537,7 @@ dependencies = [ "Inflector", "num-bigint", "roxmltree", - "syn 1.0.74", + "syn 2.0.37", "text-diff", "xml-rs", "xsd-macro-utils", diff --git a/wsdl-parser/Cargo.toml b/wsdl-parser/Cargo.toml index 521fa5aa..a83e9763 100644 --- a/wsdl-parser/Cargo.toml +++ b/wsdl-parser/Cargo.toml @@ -15,6 +15,6 @@ Inflector = "0.11" roxmltree = "0.14" [dev-dependencies] -syn = { version = "1", features = ["full"] } +syn = { version = "2", features = ["full", "extra-traits"] } text-diff = "0.4" xsd-parser = { path = "../xsd-parser" } diff --git a/xsd-macro-utils/Cargo.toml b/xsd-macro-utils/Cargo.toml index 91b21e9a..13a59d13 100644 --- a/xsd-macro-utils/Cargo.toml +++ b/xsd-macro-utils/Cargo.toml @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0" [dependencies] proc-macro2 = "1" quote = "1" -syn = "1" +syn = "2" [lib] proc-macro = true diff --git a/xsd-parser/Cargo.toml b/xsd-parser/Cargo.toml index 412bd411..432b87b8 100644 --- a/xsd-parser/Cargo.toml +++ b/xsd-parser/Cargo.toml @@ -16,7 +16,7 @@ roxmltree = "0.14" [dev-dependencies] num-bigint = "0.4" -syn = { version = "1", features = ["full"] } +syn = { version = "2", features = ["full", "extra-traits"] } text-diff = "0.4" xml-rs = "0.8" xsd-macro-utils = { path = "../xsd-macro-utils" } From f2395a729aabbb8d1f1ee46af09a407e2b4078a1 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 19:35:29 +0700 Subject: [PATCH 5/8] Upgrade `bigdecimal` --- Cargo.lock | 12 ++++++++++-- xsd-types/Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37299caf..77d95d21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,10 +83,12 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bigdecimal" -version = "0.3.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +checksum = "454bca3db10617b88b566f205ed190aedb0e0e6dd4cad61d3988a72e8c5594cb" dependencies = [ + "autocfg", + "libm", "num-bigint", "num-integer", "num-traits", @@ -203,6 +205,12 @@ version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +[[package]] +name = "libm" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" + [[package]] name = "log" version = "0.4.14" diff --git a/xsd-types/Cargo.toml b/xsd-types/Cargo.toml index decf8ad9..588e846e 100644 --- a/xsd-types/Cargo.toml +++ b/xsd-types/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" license = "MIT OR Apache-2.0" [dependencies] -bigdecimal = "0.3" +bigdecimal = "0.4" chrono = "0.4" num-bigint = "0.4" xml-rs = "0.8" From a62c0bee288e4f6e812b6c300829abee77d75775 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 19:42:59 +0700 Subject: [PATCH 6/8] Remove newline at test XMLs beginning Otherwise, some tests fail. --- xsd-types/src/types/date.rs | 6 ++---- xsd-types/src/types/datetime.rs | 6 ++---- xsd-types/src/types/datetimestamp.rs | 6 ++---- xsd-types/src/types/decimal.rs | 6 ++---- xsd-types/src/types/gday.rs | 6 ++---- xsd-types/src/types/gmonth.rs | 6 ++---- xsd-types/src/types/gmonthday.rs | 6 ++---- xsd-types/src/types/gyear.rs | 6 ++---- xsd-types/src/types/gyearmonth.rs | 6 ++---- xsd-types/src/types/integer.rs | 6 ++---- xsd-types/src/types/negative_integer.rs | 6 ++---- xsd-types/src/types/non_negative_integer.rs | 6 ++---- xsd-types/src/types/non_positive_integer.rs | 6 ++---- xsd-types/src/types/positive_integer.rs | 6 ++---- xsd-types/src/types/time.rs | 6 ++---- 15 files changed, 30 insertions(+), 60 deletions(-) diff --git a/xsd-types/src/types/date.rs b/xsd-types/src/types/date.rs index fdb25cbb..1eb27a35 100644 --- a/xsd-types/src/types/date.rs +++ b/xsd-types/src/types/date.rs @@ -188,8 +188,7 @@ mod tests { #[test] fn date_serialize_test() { - let expected = r#" - + let expected = r#" 2020-02-02+06:30 Hello world @@ -208,8 +207,7 @@ mod tests { #[test] fn date_deserialize_test() { - let s = r#" - + let s = r#" 2020-02-02-06:30 Hello world diff --git a/xsd-types/src/types/datetime.rs b/xsd-types/src/types/datetime.rs index 8e0af854..78e47a48 100644 --- a/xsd-types/src/types/datetime.rs +++ b/xsd-types/src/types/datetime.rs @@ -138,8 +138,7 @@ mod tests { #[test] fn datetime_serialize_test() { - let expected = r#" - + let expected = r#" 2020-03-07T04:40:00+06:30 Hello world @@ -159,8 +158,7 @@ mod tests { #[test] fn datetime_deserialize_test() { - let s = r#" - + let s = r#" 2020-03-07T04:40:00-06:30 Hello world diff --git a/xsd-types/src/types/datetimestamp.rs b/xsd-types/src/types/datetimestamp.rs index c887b96b..581c61ba 100644 --- a/xsd-types/src/types/datetimestamp.rs +++ b/xsd-types/src/types/datetimestamp.rs @@ -120,8 +120,7 @@ mod tests { #[test] fn datetime_serialize_test() { - let expected = r#" - + let expected = r#" 2020-03-07T04:40:00+06:30 Hello world @@ -141,8 +140,7 @@ mod tests { #[test] fn datetime_deserialize_test() { - let s = r#" - + let s = r#" 2020-03-07T04:40:00-06:30 Hello world diff --git a/xsd-types/src/types/decimal.rs b/xsd-types/src/types/decimal.rs index 2951b45c..d98347b9 100644 --- a/xsd-types/src/types/decimal.rs +++ b/xsd-types/src/types/decimal.rs @@ -49,8 +49,7 @@ mod tests { #[test] fn integer_serialize_test() { - let expected = r#" - + let expected = r#" 0.01234 -12.34 @@ -67,8 +66,7 @@ mod tests { #[test] fn integer_deserialize_test() { // Value "+0.01234" is used to check optional plus sign deserialization. - let s = r#" - + let s = r#" +0.01234 -12.34 diff --git a/xsd-types/src/types/gday.rs b/xsd-types/src/types/gday.rs index be23d716..71a6bf67 100644 --- a/xsd-types/src/types/gday.rs +++ b/xsd-types/src/types/gday.rs @@ -191,8 +191,7 @@ mod tests { #[test] fn gday_serialize_test() { - let expected = r#" - + let expected = r#" ---07+06:30 Hello world @@ -211,8 +210,7 @@ mod tests { #[test] fn gday_deserialize_test() { - let s = r#" - + let s = r#" ---29-06:30 Hello world diff --git a/xsd-types/src/types/gmonth.rs b/xsd-types/src/types/gmonth.rs index fedca307..16fdc724 100644 --- a/xsd-types/src/types/gmonth.rs +++ b/xsd-types/src/types/gmonth.rs @@ -191,8 +191,7 @@ mod tests { #[test] fn gmonth_serialize_test() { - let expected = r#" - + let expected = r#" --07+06:30 Hello world @@ -211,8 +210,7 @@ mod tests { #[test] fn gmonth_deserialize_test() { - let s = r#" - + let s = r#" --09-06:30 Hello world diff --git a/xsd-types/src/types/gmonthday.rs b/xsd-types/src/types/gmonthday.rs index 37ef525c..a62d440c 100644 --- a/xsd-types/src/types/gmonthday.rs +++ b/xsd-types/src/types/gmonthday.rs @@ -246,8 +246,7 @@ mod tests { #[test] fn gmonthday_serialize_test() { - let expected = r#" - + let expected = r#" --07-09+06:30 Hello world @@ -267,8 +266,7 @@ mod tests { #[test] fn gmonthday_deserialize_test() { - let s = r#" - + let s = r#" --07-09-06:30 Hello world diff --git a/xsd-types/src/types/gyear.rs b/xsd-types/src/types/gyear.rs index 908b8e26..c1be3197 100644 --- a/xsd-types/src/types/gyear.rs +++ b/xsd-types/src/types/gyear.rs @@ -244,8 +244,7 @@ mod tests { #[test] fn gyear_serialize_test() { - let expected = r#" - + let expected = r#" 2007+06:30 Hello world @@ -264,8 +263,7 @@ mod tests { #[test] fn gyear_deserialize_test() { - let s = r#" - + let s = r#" 2007-06:30 Hello world diff --git a/xsd-types/src/types/gyearmonth.rs b/xsd-types/src/types/gyearmonth.rs index 35931c68..cd7fd807 100644 --- a/xsd-types/src/types/gyearmonth.rs +++ b/xsd-types/src/types/gyearmonth.rs @@ -301,8 +301,7 @@ mod tests { #[test] fn gyearmonth_serialize_test() { - let expected = r#" - + let expected = r#" 2007-02+06:30 Hello world @@ -322,8 +321,7 @@ mod tests { #[test] fn gyearmonth_deserialize_test() { - let s = r#" - + let s = r#" 2007-02-06:30 Hello world diff --git a/xsd-types/src/types/integer.rs b/xsd-types/src/types/integer.rs index c7ca0dcf..3638d0cf 100644 --- a/xsd-types/src/types/integer.rs +++ b/xsd-types/src/types/integer.rs @@ -91,8 +91,7 @@ mod tests { #[test] fn integer_serialize_test() { - let expected = r#" - + let expected = r#" 1234 -1234 @@ -109,8 +108,7 @@ mod tests { #[test] fn integer_deserialize_test() { // Value "+1234" is used to check optional plus sign deserialization. - let s = r#" - + let s = r#" +1234 -1234 diff --git a/xsd-types/src/types/negative_integer.rs b/xsd-types/src/types/negative_integer.rs index 7d4a7c08..59961f17 100644 --- a/xsd-types/src/types/negative_integer.rs +++ b/xsd-types/src/types/negative_integer.rs @@ -102,8 +102,7 @@ mod tests { #[test] fn negative_integer_serialize_test() { - let expected = r#" - + let expected = r#" -1 -1234 @@ -119,8 +118,7 @@ mod tests { #[test] fn negative_integer_deserialize_test() { - let s = r#" - + let s = r#" -1 -1234 diff --git a/xsd-types/src/types/non_negative_integer.rs b/xsd-types/src/types/non_negative_integer.rs index 3cfe189b..d53f79a2 100644 --- a/xsd-types/src/types/non_negative_integer.rs +++ b/xsd-types/src/types/non_negative_integer.rs @@ -99,8 +99,7 @@ mod tests { #[test] fn non_negative_integer_serialize_test() { - let expected = r#" - + let expected = r#" 1234 0 @@ -117,8 +116,7 @@ mod tests { #[test] fn non_negative_integer_deserialize_test() { // Value "+1234" is used to check optional plus sign deserialization. - let s = r#" - + let s = r#" +1234 0 diff --git a/xsd-types/src/types/non_positive_integer.rs b/xsd-types/src/types/non_positive_integer.rs index 7f787203..134e3d88 100644 --- a/xsd-types/src/types/non_positive_integer.rs +++ b/xsd-types/src/types/non_positive_integer.rs @@ -109,8 +109,7 @@ mod tests { #[test] fn non_positive_integer_serialize_test() { - let expected = r#" - + let expected = r#" 0 -1234 @@ -126,8 +125,7 @@ mod tests { #[test] fn non_positive_integer_deserialize_test() { - let s = r#" - + let s = r#" 0 -1234 diff --git a/xsd-types/src/types/positive_integer.rs b/xsd-types/src/types/positive_integer.rs index 2d693ac2..d91f21ed 100644 --- a/xsd-types/src/types/positive_integer.rs +++ b/xsd-types/src/types/positive_integer.rs @@ -95,8 +95,7 @@ mod tests { #[test] fn positive_integer_serialize_test() { - let expected = r#" - + let expected = r#" 1234 1 @@ -113,8 +112,7 @@ mod tests { #[test] fn positive_integer_deserialize_test() { // Value "+1234" is used to check optional plus sign deserialization. - let s = r#" - + let s = r#" +1234 1 diff --git a/xsd-types/src/types/time.rs b/xsd-types/src/types/time.rs index 4abd65e4..8018aaac 100644 --- a/xsd-types/src/types/time.rs +++ b/xsd-types/src/types/time.rs @@ -192,8 +192,7 @@ mod tests { #[test] fn datetime_serialize_test() { - let expected = r#" - + let expected = r#" 04:40:00+06:30 Hello world @@ -212,8 +211,7 @@ mod tests { #[test] fn integer_deserialize_test() { - let s = r#" - + let s = r#" 04:40:00-06:30 Hello world From fc82a359cf18d03cc1d21b96855ff29fafaa2c96 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 19:43:10 +0700 Subject: [PATCH 7/8] Run `cargo update` --- Cargo.lock | 266 ++++++++++++++++++--------- xsd-types/src/types/date.rs | 43 +++-- xsd-types/src/types/datetime.rs | 80 +++++--- xsd-types/src/types/datetimestamp.rs | 80 +++++--- xsd-types/src/types/gday.rs | 18 +- xsd-types/src/types/gmonth.rs | 18 +- xsd-types/src/types/gmonthday.rs | 18 +- xsd-types/src/types/gyear.rs | 26 +-- xsd-types/src/types/gyearmonth.rs | 26 +-- xsd-types/src/types/time.rs | 43 +++-- xsd-types/src/types/utils.rs | 22 ++- 11 files changed, 409 insertions(+), 231 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77d95d21..68d1a542 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,13 +14,28 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.4" @@ -71,15 +86,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.42" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bigdecimal" @@ -94,6 +109,21 @@ dependencies = [ "num-traits", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -102,15 +132,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ - "libc", - "num-integer", + "android-tzdata", + "iana-time-zone", + "js-sys", "num-traits", - "time", - "winapi 0.3.9", + "wasm-bindgen", + "windows-targets", ] [[package]] @@ -159,6 +190,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "getopts" version = "0.2.21" @@ -183,13 +220,45 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" dependencies = [ - "winapi 0.2.8", + "winapi", "winapi-build", ] @@ -201,9 +270,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.99" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libm" @@ -213,24 +282,21 @@ checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" [[package]] name = "log" -version = "0.4.14" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.4.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "num-bigint" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74e768dff5fb39a41b3bcd30bb25cf989706c90d028d1ad71971987aa309d535" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ "autocfg", "num-integer", @@ -239,9 +305,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", @@ -249,13 +315,19 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + [[package]] name = "proc-macro2" version = "1.0.67" @@ -276,9 +348,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ "aho-corasick", "memchr", @@ -287,9 +371,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "roxmltree" @@ -308,13 +392,13 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.74" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -335,7 +419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2077e54d38055cf1ca0fd7933a2e00cd3ec8f6fed352b2a377f06dcdaaf3281" dependencies = [ "kernel32-sys", - "winapi 0.2.8", + "winapi", ] [[package]] @@ -348,17 +432,6 @@ dependencies = [ "term", ] -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi 0.3.9", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -367,21 +440,15 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "utf8parse" @@ -390,44 +457,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +name = "wasm-bindgen" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] [[package]] -name = "winapi" -version = "0.2.8" +name = "wasm-bindgen-backend" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.37", + "wasm-bindgen-shared", +] [[package]] -name = "winapi" -version = "0.3.9" +name = "wasm-bindgen-macro" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "quote", + "wasm-bindgen-macro-support", ] [[package]] -name = "winapi-build" -version = "0.1.1" +name = "wasm-bindgen-macro-support" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "wasm-bindgen-shared" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "winapi" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] [[package]] name = "windows-sys" @@ -519,15 +621,15 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.4" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" +checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "xmlparser" -version = "0.13.3" +version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" [[package]] name = "xsd-macro-utils" @@ -596,6 +698,6 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 1.0.74", + "syn 1.0.109", "xml-rs", ] diff --git a/xsd-types/src/types/date.rs b/xsd-types/src/types/date.rs index 1eb27a35..def40b49 100644 --- a/xsd-types/src/types/date.rs +++ b/xsd-types/src/types/date.rs @@ -26,7 +26,7 @@ impl Date { impl Default for Date { fn default() -> Date { Self { - value: NaiveDate::from_ymd(1, 1, 1), + value: NaiveDate::from_ymd_opt(1, 1, 1).unwrap(), timezone: None, } } @@ -43,7 +43,7 @@ impl FromStr for Date { if let Some(s) = s.strip_suffix('Z') { return Ok(Date { value: parse_naive_date(s)?, - timezone: Some(FixedOffset::east(0)), + timezone: Some(FixedOffset::east_opt(0).unwrap()), }); } @@ -100,7 +100,7 @@ mod tests { assert_eq!( Date::from_str("2020-02-02"), Ok(Date { - value: NaiveDate::from_ymd(2020, 2, 2), + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), timezone: None }) ); @@ -109,8 +109,8 @@ mod tests { assert_eq!( Date::from_str("2020-02-02Z"), Ok(Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::east(0)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -118,8 +118,8 @@ mod tests { assert_eq!( Date::from_str("2020-02-02+06:30"), Ok(Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -127,8 +127,8 @@ mod tests { assert_eq!( Date::from_str("2020-02-02-06:30"), Ok(Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); } @@ -138,7 +138,7 @@ mod tests { // No timezone. assert_eq!( Date { - value: NaiveDate::from_ymd(2020, 2, 2), + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), timezone: None } .to_string(), @@ -148,8 +148,8 @@ mod tests { // Timezone +00:00. assert_eq!( Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::east(0)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "2020-02-02+00:00" @@ -158,8 +158,8 @@ mod tests { // Positive offset. assert_eq!( Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "2020-02-02+06:30" @@ -168,8 +168,8 @@ mod tests { // Negative offset. assert_eq!( Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "2020-02-02-06:30" @@ -196,8 +196,8 @@ mod tests { "#; let m = Message { created_at: Date { - value: NaiveDate::from_ymd(2020, 2, 2), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -214,10 +214,13 @@ mod tests { "#; let m: Message = yaserde::de::from_str(s).unwrap(); - assert_eq!(m.created_at.value, NaiveDate::from_ymd(2020, 2, 2)); + assert_eq!( + m.created_at.value, + NaiveDate::from_ymd_opt(2020, 2, 2).unwrap() + ); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/datetime.rs b/xsd-types/src/types/datetime.rs index 78e47a48..643bfa89 100644 --- a/xsd-types/src/types/datetime.rs +++ b/xsd-types/src/types/datetime.rs @@ -64,9 +64,13 @@ mod tests { #[test] fn datetime_parse_test() { // No timezone. - let offset = FixedOffset::east(0); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(0).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime::from_str("2020-03-07T04:40:00"), Ok(DateTime { value: dt }) @@ -78,18 +82,26 @@ mod tests { ); // Positive offset. - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime::from_str("2020-03-07T04:40:00+06:30"), Ok(DateTime { value: dt }) ); // Negative offset. - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime::from_str("2020-03-07T04:40:00-06:30"), Ok(DateTime { value: dt }) @@ -99,27 +111,39 @@ mod tests { #[test] fn datetime_display_test() { // Timezone +00:00. - let offset = FixedOffset::east(0); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(0).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime { value: dt }.to_string(), "2020-03-07T04:40:00+00:00" ); // Positive offset. - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime { value: dt }.to_string(), "2020-03-07T04:40:00+06:30" ); // Negative offset. - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTime { value: dt }.to_string(), "2020-03-07T04:40:00-06:30" @@ -145,9 +169,13 @@ mod tests { "#; - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); let m = Message { created_at: DateTime { value: dt }, text: "Hello world".to_string(), @@ -166,9 +194,13 @@ mod tests { "#; let m: Message = yaserde::de::from_str(s).unwrap(); - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!(m.created_at.value, dt); assert_eq!(m.text, "Hello world".to_string()); diff --git a/xsd-types/src/types/datetimestamp.rs b/xsd-types/src/types/datetimestamp.rs index 581c61ba..e853f812 100644 --- a/xsd-types/src/types/datetimestamp.rs +++ b/xsd-types/src/types/datetimestamp.rs @@ -49,9 +49,13 @@ mod tests { #[test] fn datetime_parse_test() { // No timezone. - let offset = FixedOffset::east(0); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(0).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert!(DateTimeStamp::from_str("2020-03-07T04:40:00").is_err()); // Timezone "Z". assert_eq!( @@ -60,18 +64,26 @@ mod tests { ); // Positive offset. - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTimeStamp::from_str("2020-03-07T04:40:00+06:30"), Ok(DateTimeStamp::from_chrono_datetime(dt)) ); // Negative offset. - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTimeStamp::from_str("2020-03-07T04:40:00-06:30"), Ok(DateTimeStamp::from_chrono_datetime(dt)) @@ -81,27 +93,39 @@ mod tests { #[test] fn datetime_display_test() { // Timezone +00:00. - let offset = FixedOffset::east(0); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(0).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTimeStamp::from_chrono_datetime(dt).to_string(), "2020-03-07T04:40:00+00:00" ); // Positive offset. - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTimeStamp::from_chrono_datetime(dt).to_string(), "2020-03-07T04:40:00+06:30" ); // Negative offset. - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!( DateTimeStamp::from_chrono_datetime(dt).to_string(), "2020-03-07T04:40:00-06:30" @@ -127,9 +151,13 @@ mod tests { "#; - let offset = FixedOffset::east(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); let m = Message { created_at: DateTimeStamp::from_chrono_datetime(dt), text: "Hello world".to_string(), @@ -148,9 +176,13 @@ mod tests { "#; let m: Message = yaserde::de::from_str(s).unwrap(); - let offset = FixedOffset::west(6 * 3600 + 30 * 60); - let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset; - let dt = CDateTime::::from_utc(dt_utc, offset); + let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap(); + let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7) + .unwrap() + .and_hms_opt(4, 40, 0) + .unwrap() + - offset; + let dt = CDateTime::::from_naive_utc_and_offset(dt_utc, offset); assert_eq!(m.created_at.value, DateTime::from_chrono_datetime(dt)); assert_eq!(m.text, "Hello world".to_string()); diff --git a/xsd-types/src/types/gday.rs b/xsd-types/src/types/gday.rs index 71a6bf67..6656410e 100644 --- a/xsd-types/src/types/gday.rs +++ b/xsd-types/src/types/gday.rs @@ -48,7 +48,7 @@ impl FromStr for GDay { } if let Some(s) = s.strip_suffix('Z') { - return GDay::new(parse_value(s)?, Some(FixedOffset::east(0))); + return GDay::new(parse_value(s)?, Some(FixedOffset::east_opt(0).unwrap())); } if s.contains('+') { @@ -104,7 +104,7 @@ mod tests { GDay::from_str("---25Z"), Ok(GDay { value: 25, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -113,7 +113,7 @@ mod tests { GDay::from_str("---25+06:30"), Ok(GDay { value: 25, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -122,7 +122,7 @@ mod tests { GDay::from_str("---25-06:30"), Ok(GDay { value: 25, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -152,7 +152,7 @@ mod tests { assert_eq!( GDay { value: 3, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "---03+00:00" @@ -162,7 +162,7 @@ mod tests { assert_eq!( GDay { value: 3, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "---03+06:30" @@ -172,7 +172,7 @@ mod tests { assert_eq!( GDay { value: 3, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "---03-06:30" @@ -200,7 +200,7 @@ mod tests { let m = Message { created_at: GDay { value: 7, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -220,7 +220,7 @@ mod tests { assert_eq!(m.created_at.value, 29); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/gmonth.rs b/xsd-types/src/types/gmonth.rs index 16fdc724..9745bcfb 100644 --- a/xsd-types/src/types/gmonth.rs +++ b/xsd-types/src/types/gmonth.rs @@ -48,7 +48,7 @@ impl FromStr for GMonth { } if let Some(s) = s.strip_suffix('Z') { - return GMonth::new(parse_value(s)?, Some(FixedOffset::east(0))); + return GMonth::new(parse_value(s)?, Some(FixedOffset::east_opt(0).unwrap())); } if s.contains('+') { @@ -104,7 +104,7 @@ mod tests { GMonth::from_str("--12Z"), Ok(GMonth { value: 12, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -113,7 +113,7 @@ mod tests { GMonth::from_str("--12+06:30"), Ok(GMonth { value: 12, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -122,7 +122,7 @@ mod tests { GMonth::from_str("--12-06:30"), Ok(GMonth { value: 12, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -152,7 +152,7 @@ mod tests { assert_eq!( GMonth { value: 3, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "--03+00:00" @@ -162,7 +162,7 @@ mod tests { assert_eq!( GMonth { value: 3, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "--03+06:30" @@ -172,7 +172,7 @@ mod tests { assert_eq!( GMonth { value: 3, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "--03-06:30" @@ -200,7 +200,7 @@ mod tests { let m = Message { created_at: GMonth { value: 7, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -220,7 +220,7 @@ mod tests { assert_eq!(m.created_at.value, 9); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/gmonthday.rs b/xsd-types/src/types/gmonthday.rs index a62d440c..b72a3072 100644 --- a/xsd-types/src/types/gmonthday.rs +++ b/xsd-types/src/types/gmonthday.rs @@ -87,7 +87,7 @@ impl FromStr for GMonthDay { if let Some(s) = s.strip_suffix('Z') { let (month, day) = parse_value(s)?; - return GMonthDay::new(month, day, Some(FixedOffset::east(0))); + return GMonthDay::new(month, day, Some(FixedOffset::east_opt(0).unwrap())); } if s.contains('+') { @@ -148,7 +148,7 @@ mod tests { Ok(GMonthDay { month: 12, day: 20, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -158,7 +158,7 @@ mod tests { Ok(GMonthDay { month: 12, day: 20, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -168,7 +168,7 @@ mod tests { Ok(GMonthDay { month: 12, day: 20, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -205,7 +205,7 @@ mod tests { GMonthDay { month: 3, day: 2, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "--03-02+00:00" @@ -216,7 +216,7 @@ mod tests { GMonthDay { month: 3, day: 2, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "--03-02+06:30" @@ -227,7 +227,7 @@ mod tests { GMonthDay { month: 3, day: 2, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "--03-02-06:30" @@ -256,7 +256,7 @@ mod tests { created_at: GMonthDay { month: 7, day: 9, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -277,7 +277,7 @@ mod tests { assert_eq!(m.created_at.day, 9); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/gyear.rs b/xsd-types/src/types/gyear.rs index c1be3197..b75a2f1c 100644 --- a/xsd-types/src/types/gyear.rs +++ b/xsd-types/src/types/gyear.rs @@ -56,7 +56,7 @@ fn parse_str_positive(s: &str) -> Result { } if let Some(s) = s.strip_suffix('Z') { - return GYear::new(parse_value(s)?, Some(FixedOffset::east(0))); + return GYear::new(parse_value(s)?, Some(FixedOffset::east_opt(0).unwrap())); } if s.contains('+') { @@ -122,7 +122,7 @@ mod tests { GYear::from_str("2020Z"), Ok(GYear { value: 2020, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -131,7 +131,7 @@ mod tests { GYear::from_str("2020+06:30"), Ok(GYear { value: 2020, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -140,7 +140,7 @@ mod tests { GYear::from_str("2020-06:30"), Ok(GYear { value: 2020, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -149,7 +149,7 @@ mod tests { GYear::from_str("-0020-06:30"), Ok(GYear { value: -20, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -158,7 +158,7 @@ mod tests { GYear::from_str("-20000-06:30"), Ok(GYear { value: -20000, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -185,7 +185,7 @@ mod tests { assert_eq!( GYear { value: 987, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "0987+00:00" @@ -195,7 +195,7 @@ mod tests { assert_eq!( GYear { value: 987, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "0987+06:30" @@ -205,7 +205,7 @@ mod tests { assert_eq!( GYear { value: 987, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "0987-06:30" @@ -215,7 +215,7 @@ mod tests { assert_eq!( GYear { value: -987, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "-0987-06:30" @@ -225,7 +225,7 @@ mod tests { assert_eq!( GYear { value: -98765, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "-98765-06:30" @@ -253,7 +253,7 @@ mod tests { let m = Message { created_at: GYear { value: 2007, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -273,7 +273,7 @@ mod tests { assert_eq!(m.created_at.value, 2007); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/gyearmonth.rs b/xsd-types/src/types/gyearmonth.rs index cd7fd807..8056c690 100644 --- a/xsd-types/src/types/gyearmonth.rs +++ b/xsd-types/src/types/gyearmonth.rs @@ -97,7 +97,7 @@ fn parse_str_positive(s: &str) -> Result { if let Some(s) = s.strip_suffix('Z') { let (year, month) = parse_value(s)?; - return GYearMonth::new(year, month, Some(FixedOffset::east(0))); + return GYearMonth::new(year, month, Some(FixedOffset::east_opt(0).unwrap())); } if s.contains('+') { @@ -164,7 +164,7 @@ mod tests { Ok(GYearMonth { year: 2020, month: 3, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -174,7 +174,7 @@ mod tests { Ok(GYearMonth { year: 2020, month: 3, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -184,7 +184,7 @@ mod tests { Ok(GYearMonth { year: 2020, month: 3, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -194,7 +194,7 @@ mod tests { Ok(GYearMonth { year: -20, month: 3, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -204,7 +204,7 @@ mod tests { Ok(GYearMonth { year: -20000, month: 3, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -238,7 +238,7 @@ mod tests { GYearMonth { year: 987, month: 6, - timezone: Some(FixedOffset::east(0)) + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "0987-06+00:00" @@ -249,7 +249,7 @@ mod tests { GYearMonth { year: 987, month: 6, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "0987-06+06:30" @@ -260,7 +260,7 @@ mod tests { GYearMonth { year: 987, month: 6, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "0987-06-06:30" @@ -271,7 +271,7 @@ mod tests { GYearMonth { year: -987, month: 6, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "-0987-06-06:30" @@ -282,7 +282,7 @@ mod tests { GYearMonth { year: -98765, month: 6, - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "-98765-06-06:30" @@ -311,7 +311,7 @@ mod tests { created_at: GYearMonth { year: 2007, month: 2, - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -332,7 +332,7 @@ mod tests { assert_eq!(m.created_at.month, 2); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)), + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()), ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/time.rs b/xsd-types/src/types/time.rs index 8018aaac..3ab6f538 100644 --- a/xsd-types/src/types/time.rs +++ b/xsd-types/src/types/time.rs @@ -26,7 +26,7 @@ impl Time { impl Default for Time { fn default() -> Time { Self { - value: NaiveTime::from_hms(0, 0, 0), + value: NaiveTime::from_hms_opt(0, 0, 0).unwrap(), timezone: None, } } @@ -43,7 +43,7 @@ impl FromStr for Time { if let Some(s) = s.strip_suffix('Z') { return Ok(Time { value: parse_naive_time(s)?, - timezone: Some(FixedOffset::east(0)), + timezone: Some(FixedOffset::east_opt(0).unwrap()), }); } @@ -104,7 +104,7 @@ mod tests { assert_eq!( Time::from_str("04:40:00"), Ok(Time { - value: NaiveTime::from_hms(4, 40, 0), + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), timezone: None }) ); @@ -113,8 +113,8 @@ mod tests { assert_eq!( Time::from_str("04:40:00Z"), Ok(Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::east(0)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::east_opt(0).unwrap()) }) ); @@ -122,8 +122,8 @@ mod tests { assert_eq!( Time::from_str("04:40:00+06:30"), Ok(Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) }) ); @@ -131,8 +131,8 @@ mod tests { assert_eq!( Time::from_str("04:40:00-06:30"), Ok(Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) }) ); } @@ -142,7 +142,7 @@ mod tests { // No timezone. assert_eq!( Time { - value: NaiveTime::from_hms(4, 40, 0), + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), timezone: None } .to_string(), @@ -152,8 +152,8 @@ mod tests { // Timezone +00:00. assert_eq!( Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::east(0)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::east_opt(0).unwrap()) } .to_string(), "04:40:00+00:00" @@ -162,8 +162,8 @@ mod tests { // Positive offset. assert_eq!( Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "04:40:00+06:30" @@ -172,8 +172,8 @@ mod tests { // Negative offset. assert_eq!( Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60)) + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) } .to_string(), "04:40:00-06:30" @@ -200,8 +200,8 @@ mod tests { "#; let m = Message { created_at: Time { - value: NaiveTime::from_hms(4, 40, 0), - timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)), + value: NaiveTime::from_hms_opt(4, 40, 0).unwrap(), + timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()), }, text: "Hello world".to_string(), }; @@ -218,10 +218,13 @@ mod tests { "#; let m: Message = yaserde::de::from_str(s).unwrap(); - assert_eq!(m.created_at.value, NaiveTime::from_hms(4, 40, 0)); + assert_eq!( + m.created_at.value, + NaiveTime::from_hms_opt(4, 40, 0).unwrap() + ); assert_eq!( m.created_at.timezone, - Some(FixedOffset::west(6 * 3600 + 30 * 60)) + Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) ); assert_eq!(m.text, "Hello world".to_string()); } diff --git a/xsd-types/src/types/utils.rs b/xsd-types/src/types/utils.rs index f2cd6bb1..4a3a75ce 100644 --- a/xsd-types/src/types/utils.rs +++ b/xsd-types/src/types/utils.rs @@ -3,7 +3,7 @@ use chrono::FixedOffset; // Parses ISO 8601 timezone. pub fn parse_timezone(s: &str) -> Result { if s == "Z" { - return Ok(FixedOffset::east(0)); + return Ok(FixedOffset::east_opt(0).unwrap()); } let tokens: Vec<&str> = s[1..].split(':').collect(); @@ -23,8 +23,8 @@ pub fn parse_timezone(s: &str) -> Result { let offset_secs = 60 * (60 * hours + minutes); match s.chars().next().unwrap() { - '+' => Ok(FixedOffset::east(offset_secs)), - '-' => Ok(FixedOffset::west(offset_secs)), + '+' => FixedOffset::east_opt(offset_secs).ok_or("Seconds out of bound".to_owned()), + '-' => FixedOffset::west_opt(offset_secs).ok_or("Seconds out of bound".to_owned()), _ => Err("bad timezone format: timezone should start with '+' or '-'".to_string()), } } @@ -36,25 +36,31 @@ mod tests { #[test] fn timezone_parse_test() { // Timezone "Z". - assert_eq!(parse_timezone("Z"), Ok(FixedOffset::east(0))); + assert_eq!(parse_timezone("Z"), Ok(FixedOffset::east_opt(0).unwrap())); // Positive offset. assert_eq!( parse_timezone("+06:30"), - Ok(FixedOffset::east(6 * 3600 + 30 * 60)) + Ok(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()) ); // Negative offset. assert_eq!( parse_timezone("-06:30"), - Ok(FixedOffset::west(6 * 3600 + 30 * 60)) + Ok(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()) ); // Positive offset max. - assert_eq!(parse_timezone("+14:00"), Ok(FixedOffset::east(14 * 3600))); + assert_eq!( + parse_timezone("+14:00"), + Ok(FixedOffset::east_opt(14 * 3600).unwrap()) + ); // Negative offset max. - assert_eq!(parse_timezone("-14:00"), Ok(FixedOffset::west(14 * 3600))); + assert_eq!( + parse_timezone("-14:00"), + Ok(FixedOffset::west_opt(14 * 3600).unwrap()) + ); // Invalid values. assert!(parse_timezone("06:30").is_err()); From 28e109b42c9956b139434222cb0278a00572dcc4 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 3 Oct 2023 20:06:48 +0700 Subject: [PATCH 8/8] Remove `block-fixup` action --- .github/workflows/git.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .github/workflows/git.yml diff --git a/.github/workflows/git.yml b/.github/workflows/git.yml deleted file mode 100644 index 2d5332ce..00000000 --- a/.github/workflows/git.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Git Checks - -on: [pull_request] - -jobs: - block-fixup: - runs-on: ubuntu-18.04 - - steps: - - uses: actions/checkout@v2.0.0 - - name: Check fixup commits. Rebase w/ autosquash required if this fails. - uses: 13rac1/block-fixup-merge-action@v2.0.0