diff --git a/.mise.toml b/.mise.toml index e89364c..7423e72 100644 --- a/.mise.toml +++ b/.mise.toml @@ -21,6 +21,7 @@ run = [ ] [tasks.check] +wait_for = ["generate"] run = "cargo hack check --each-feature" # no uncommitted changes on sdk (generated code) @@ -40,6 +41,7 @@ cargo deny --workspace --all-features \ """ [tasks."lint:cargo_clippy"] +wait_for = ["generate"] run = "cargo clippy --workspace --all-features --no-deps --all-targets -- --deny warnings" [tasks."lint:toml"] diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 9ff08ad..b9093a2 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -12,12 +12,12 @@ description = "A Rust SDK for CDEvents" [dependencies] cloudevents-sdk = { version = "0.9", optional = true, default-features = false } -fluent-uri = "0.3" -proptest = { version = "1.4", optional = true } +fluent-uri = { version = "0.4", features = ["serde"] } +proptest = { version = "1", optional = true } proptest-derive = { version = "0.7", optional = true } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -thiserror = "2.0" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +thiserror = "2" time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] @@ -25,7 +25,7 @@ assert-json-diff = "2.0" boon = "0.6" glob = "0.3" proptest = "1" -regex = "1.10" +regex = "1" rstest = "0.26" [features] diff --git a/cdevents-sdk/src/error.rs b/cdevents-sdk/src/error.rs index acf0c47..bb0831d 100644 --- a/cdevents-sdk/src/error.rs +++ b/cdevents-sdk/src/error.rs @@ -7,11 +7,13 @@ pub enum Error { #[error("Empty data in cloudevent")] DataNotFoundInCloudEvent, #[error(transparent)] - UriParseError( #[from] fluent_uri::error::ParseError), + UriParseError( #[from] fluent_uri::ParseError), #[error(transparent)] SerdeJsonError( #[from] serde_json::Error), #[error("unknown error")] Unknown, #[error("{0} should be non-empty")] - EmptyString(&'static str) + EmptyString(&'static str), + #[error(transparent)] + InfallibleError( #[from] std::convert::Infallible), } diff --git a/cdevents-sdk/src/serde.rs b/cdevents-sdk/src/serde.rs index c606c1a..09943c4 100644 --- a/cdevents-sdk/src/serde.rs +++ b/cdevents-sdk/src/serde.rs @@ -26,21 +26,24 @@ pub(crate) mod datetime { } } -pub(crate) mod fluent_uri { - use serde::{de::Error, Deserialize, Deserializer, Serializer}; +// pub(crate) mod fluent_uri { +// use serde::{de::Error, Deserialize, Deserializer, Serializer}; - pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - { - let txt = String::deserialize(deserializer)?; - fluent_uri::UriRef::parse(txt).map_err(D::Error::custom) - } +// pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> +// where +// D: Deserializer<'de>, +// { +// let txt = String::deserialize(deserializer)?; +// fluent_uri::UriRef::parse(txt).map_err(|e| match e { +// fluent_uri:: +// } +// D::Error::custom) +// } - pub fn serialize(input: &fluent_uri::UriRef, serializer: S) -> Result - where - S: Serializer, - { - serializer.collect_str(input.as_str()) - } -} +// pub fn serialize(input: &fluent_uri::UriRef, serializer: S) -> Result +// where +// S: Serializer, +// { +// serializer.collect_str(input.as_str()) +// } +// } diff --git a/cdevents-sdk/src/uri.rs b/cdevents-sdk/src/uri.rs index 59b670c..7309dec 100644 --- a/cdevents-sdk/src/uri.rs +++ b/cdevents-sdk/src/uri.rs @@ -15,7 +15,7 @@ use crate::UriReference; #[cfg_attr(feature = "testkit", derive(Arbitrary))] pub struct Uri( #[cfg_attr(feature = "testkit", proptest(value = "fluent_uri::UriRef::parse(\"https://example.com/\".to_owned()).unwrap()"))] //TODO generate random value - #[serde(with = "crate::serde::fluent_uri")] + //#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::UriRef ); @@ -32,7 +32,7 @@ impl FromStr for Uri { fn from_str(s: &str) -> Result { //TODO check it's not a reference URI - fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Err::from).map(Uri) + fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Err::from(e)).map(Uri) } } @@ -48,7 +48,7 @@ impl TryFrom<&str> for Uri { type Error = crate::Error; fn try_from(s: &str) -> Result { - fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Error::from).map(Uri) + fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e, _)| Self::Error::from(e)).map(Uri) } } @@ -56,7 +56,7 @@ impl TryFrom for Uri { type Error = crate::Error; fn try_from(s: String) -> Result { - fluent_uri::UriRef::parse(s).map_err(Self::Error::from).map(Uri) + fluent_uri::UriRef::parse(s).map_err(|(e, _)| Self::Error::from(e)).map(Uri) } } diff --git a/cdevents-sdk/src/uri_reference.rs b/cdevents-sdk/src/uri_reference.rs index 58952ef..6b1fea9 100644 --- a/cdevents-sdk/src/uri_reference.rs +++ b/cdevents-sdk/src/uri_reference.rs @@ -5,7 +5,7 @@ use crate::Uri; #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct UriReference( - #[serde(with = "crate::serde::fluent_uri")] + //#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::UriRef ); @@ -21,7 +21,7 @@ impl FromStr for UriReference { type Err = crate::Error; fn from_str(s: &str) -> Result { - fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Err::from).map(UriReference) + fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Err::from(e)).map(UriReference) } } @@ -29,6 +29,7 @@ impl TryFrom for UriReference { type Error = crate::Error; fn try_from(s: Uri) -> Result { + //fluent_uri::UriRef::try_from(s.0).map_err(Self::Error::from).map(UriReference) Ok(UriReference(s.0)) } } @@ -37,7 +38,7 @@ impl TryFrom<&str> for UriReference { type Error = crate::Error; fn try_from(s: &str) -> Result { - fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Error::from).map(UriReference) + fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Error::from(e)).map(UriReference) } } @@ -45,7 +46,7 @@ impl TryFrom for UriReference { type Error = crate::Error; fn try_from(s: String) -> Result { - fluent_uri::UriRef::parse(s).map_err(Self::Error::from).map(UriReference) + fluent_uri::UriRef::parse(s).map_err(|(e,_)| Self::Error::from(e)).map(UriReference) } } diff --git a/generator/Cargo.toml b/generator/Cargo.toml index 2b2662b..86958cb 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -16,7 +16,7 @@ cruet = "0.15" glob = "0.3" handlebars = { version = "6", features = ["dir_source"] } handlebars_misc_helpers = { version = "0.17", default-features = false, features = ["string", "json"] } -indexmap = "2.2" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -url = "2.5" +indexmap = "2" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +url = "2"