Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ run = [
]

[tasks.check]
wait_for = ["generate"]
run = "cargo hack check --each-feature"

# no uncommitted changes on sdk (generated code)
Expand All @@ -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"]
Expand Down
12 changes: 6 additions & 6 deletions cdevents-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ 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]
assert-json-diff = "2.0"
boon = "0.6"
glob = "0.3"
proptest = "1"
regex = "1.10"
regex = "1"
rstest = "0.26"

[features]
Expand Down
6 changes: 4 additions & 2 deletions cdevents-sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ pub enum Error {
#[error("Empty data in cloudevent")]
DataNotFoundInCloudEvent,
#[error(transparent)]
UriParseError( #[from] fluent_uri::error::ParseError<String>),
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),
}
35 changes: 19 additions & 16 deletions cdevents-sdk/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<fluent_uri::UriRef<String>, 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<fluent_uri::UriRef<String>, 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<S>(input: &fluent_uri::UriRef<String>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(input.as_str())
}
}
// pub fn serialize<S>(input: &fluent_uri::UriRef<String>, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// serializer.collect_str(input.as_str())
// }
// }
8 changes: 4 additions & 4 deletions cdevents-sdk/src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
);

Expand All @@ -32,7 +32,7 @@ impl FromStr for Uri {

fn from_str(s: &str) -> Result<Self, Self::Err> {
//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)
}
}

Expand All @@ -48,15 +48,15 @@ impl TryFrom<&str> for Uri {
type Error = crate::Error;

fn try_from(s: &str) -> Result<Self, Self::Error> {
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)
}
}

impl TryFrom<String> for Uri {
type Error = crate::Error;

fn try_from(s: String) -> Result<Self, Self::Error> {
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)
}
}

Expand Down
9 changes: 5 additions & 4 deletions cdevents-sdk/src/uri_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
);

Expand All @@ -21,14 +21,15 @@ impl FromStr for UriReference {
type Err = crate::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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)
}
}

impl TryFrom<Uri> for UriReference {
type Error = crate::Error;

fn try_from(s: Uri) -> Result<Self, Self::Error> {
//fluent_uri::UriRef::try_from(s.0).map_err(Self::Error::from).map(UriReference)
Ok(UriReference(s.0))
}
}
Expand All @@ -37,15 +38,15 @@ impl TryFrom<&str> for UriReference {
type Error = crate::Error;

fn try_from(s: &str) -> Result<Self, Self::Error> {
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)
}
}

impl TryFrom<String> for UriReference {
type Error = crate::Error;

fn try_from(s: String) -> Result<Self, Self::Error> {
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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading