Skip to content

Commit d9e593f

Browse files
committed
fix: adapt code to fluent-uri upgrade
Signed-off-by: David Bernard <[email protected]>
1 parent 8d2d0b0 commit d9e593f

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

cdevents-sdk/src/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ pub enum Error {
77
#[error("Empty data in cloudevent")]
88
DataNotFoundInCloudEvent,
99
#[error(transparent)]
10-
UriParseError( #[from] fluent_uri::error::ParseError<String>),
10+
UriParseError( #[from] fluent_uri::ParseError),
1111
#[error(transparent)]
1212
SerdeJsonError( #[from] serde_json::Error),
1313
#[error("unknown error")]
1414
Unknown,
1515
#[error("{0} should be non-empty")]
16-
EmptyString(&'static str)
16+
EmptyString(&'static str),
17+
#[error(transparent)]
18+
InfallibleError( #[from] std::convert::Infallible),
1719
}

cdevents-sdk/src/serde.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@ pub(crate) mod datetime {
2626
}
2727
}
2828

29-
pub(crate) mod fluent_uri {
30-
use serde::{de::Error, Deserialize, Deserializer, Serializer};
29+
// pub(crate) mod fluent_uri {
30+
// use serde::{de::Error, Deserialize, Deserializer, Serializer};
3131

32-
pub fn deserialize<'de, D>(deserializer: D) -> Result<fluent_uri::UriRef<String>, D::Error>
33-
where
34-
D: Deserializer<'de>,
35-
{
36-
let txt = String::deserialize(deserializer)?;
37-
fluent_uri::UriRef::parse(txt).map_err(D::Error::custom)
38-
}
32+
// pub fn deserialize<'de, D>(deserializer: D) -> Result<fluent_uri::UriRef<String>, D::Error>
33+
// where
34+
// D: Deserializer<'de>,
35+
// {
36+
// let txt = String::deserialize(deserializer)?;
37+
// fluent_uri::UriRef::parse(txt).map_err(|e| match e {
38+
// fluent_uri::
39+
// }
40+
// D::Error::custom)
41+
// }
3942

40-
pub fn serialize<S>(input: &fluent_uri::UriRef<String>, serializer: S) -> Result<S::Ok, S::Error>
41-
where
42-
S: Serializer,
43-
{
44-
serializer.collect_str(input.as_str())
45-
}
46-
}
43+
// pub fn serialize<S>(input: &fluent_uri::UriRef<String>, serializer: S) -> Result<S::Ok, S::Error>
44+
// where
45+
// S: Serializer,
46+
// {
47+
// serializer.collect_str(input.as_str())
48+
// }
49+
// }

cdevents-sdk/src/uri.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::UriReference;
1515
#[cfg_attr(feature = "testkit", derive(Arbitrary))]
1616
pub struct Uri(
1717
#[cfg_attr(feature = "testkit", proptest(value = "fluent_uri::UriRef::parse(\"https://example.com/\".to_owned()).unwrap()"))] //TODO generate random value
18-
#[serde(with = "crate::serde::fluent_uri")]
18+
//#[serde(with = "crate::serde::fluent_uri")]
1919
pub(crate) fluent_uri::UriRef<String>
2020
);
2121

@@ -32,7 +32,7 @@ impl FromStr for Uri {
3232

3333
fn from_str(s: &str) -> Result<Self, Self::Err> {
3434
//TODO check it's not a reference URI
35-
fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Err::from).map(Uri)
35+
fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Err::from(e)).map(Uri)
3636
}
3737
}
3838

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

5050
fn try_from(s: &str) -> Result<Self, Self::Error> {
51-
fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Error::from).map(Uri)
51+
fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e, _)| Self::Error::from(e)).map(Uri)
5252
}
5353
}
5454

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

5858
fn try_from(s: String) -> Result<Self, Self::Error> {
59-
fluent_uri::UriRef::parse(s).map_err(Self::Error::from).map(Uri)
59+
fluent_uri::UriRef::parse(s).map_err(|(e, _)| Self::Error::from(e)).map(Uri)
6060
}
6161
}
6262

cdevents-sdk/src/uri_reference.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::Uri;
55

66
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
77
pub struct UriReference(
8-
#[serde(with = "crate::serde::fluent_uri")]
8+
//#[serde(with = "crate::serde::fluent_uri")]
99
pub(crate) fluent_uri::UriRef<String>
1010
);
1111

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

2323
fn from_str(s: &str) -> Result<Self, Self::Err> {
24-
fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Err::from).map(UriReference)
24+
fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Err::from(e)).map(UriReference)
2525
}
2626
}
2727

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

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

3940
fn try_from(s: &str) -> Result<Self, Self::Error> {
40-
fluent_uri::UriRef::parse(s.to_owned()).map_err(Self::Error::from).map(UriReference)
41+
fluent_uri::UriRef::parse(s.to_owned()).map_err(|(e,_)| Self::Error::from(e)).map(UriReference)
4142
}
4243
}
4344

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

4748
fn try_from(s: String) -> Result<Self, Self::Error> {
48-
fluent_uri::UriRef::parse(s).map_err(Self::Error::from).map(UriReference)
49+
fluent_uri::UriRef::parse(s).map_err(|(e,_)| Self::Error::from(e)).map(UriReference)
4950
}
5051
}
5152

0 commit comments

Comments
 (0)