-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ use more precise type for uri & datetime than String
- uri => fluent_uri::Uri<String> - uri-referece => fluent_uri::Uri<String> - datetime => time::OffsetDateTime
- Loading branch information
Showing
50 changed files
with
642 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::{Context, Subject}; | ||
use serde::{ | ||
de::{self, Deserializer, MapAccess, Visitor}, | ||
Deserialize, Serialize, | ||
}; | ||
use std::fmt; | ||
|
||
#[derive(Debug, Clone, Serialize)] | ||
pub struct CDEvent { | ||
pub context: Context, | ||
pub subject: Subject, | ||
#[serde(rename = "customData", skip_serializing_if = "Option::is_none")] | ||
pub custom_data: Option<serde_json::Value>, | ||
#[serde( | ||
rename = "customDataContentType", | ||
skip_serializing_if = "Option::is_none" | ||
)] | ||
pub custom_data_content_type: Option<String>, | ||
} | ||
|
||
impl<'de> Deserialize<'de> for CDEvent { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
#[derive(Deserialize)] | ||
#[serde(field_identifier, rename_all = "camelCase")] | ||
enum Field { | ||
Context, | ||
Subject, | ||
CustomData, | ||
CustomDataContentType, | ||
} | ||
|
||
struct CDEventVisitor; | ||
|
||
impl<'de> Visitor<'de> for CDEventVisitor { | ||
type Value = CDEvent; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("struct CDEvent") | ||
} | ||
|
||
fn visit_map<V>(self, mut map: V) -> Result<CDEvent, V::Error> | ||
where | ||
V: MapAccess<'de>, | ||
{ | ||
let mut context: Option<Context> = None; | ||
let mut subject_json: Option<serde_json::value::Value> = None; | ||
let mut custom_data = None; | ||
let mut custom_data_content_type = None; | ||
while let Some(key) = map.next_key()? { | ||
match key { | ||
Field::Context => { | ||
if context.is_some() { | ||
return Err(de::Error::duplicate_field("context")); | ||
} | ||
context = Some(map.next_value()?); | ||
} | ||
Field::Subject => { | ||
if subject_json.is_some() { | ||
return Err(de::Error::duplicate_field("subject")); | ||
} | ||
subject_json = Some(map.next_value()?); | ||
} | ||
Field::CustomData => { | ||
if custom_data.is_some() { | ||
return Err(de::Error::duplicate_field("customData")); | ||
} | ||
custom_data = Some(map.next_value()?); | ||
} | ||
Field::CustomDataContentType => { | ||
if custom_data_content_type.is_some() { | ||
return Err(de::Error::duplicate_field("customDataContentType")); | ||
} | ||
custom_data_content_type = Some(map.next_value()?); | ||
} | ||
} | ||
} | ||
let context = context.ok_or_else(|| de::Error::missing_field("context"))?; | ||
let subject_json = | ||
subject_json.ok_or_else(|| de::Error::missing_field("subject"))?; | ||
let subject = | ||
Subject::from_json(&context.r#type, subject_json).map_err(de::Error::custom)?; | ||
|
||
Ok(CDEvent { | ||
context, | ||
subject, | ||
custom_data, | ||
custom_data_content_type, | ||
}) | ||
} | ||
} | ||
|
||
const FIELDS: &'static [&'static str] = &["context", "subject"]; | ||
deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Context { | ||
pub version: String, | ||
pub id: String, | ||
#[serde(with = "crate::serde::uri_reference")] | ||
pub source: fluent_uri::Uri<String>, | ||
#[serde(rename = "type")] | ||
pub r#type: String, | ||
#[serde(with = "crate::serde::datetime")] | ||
pub timestamp: time::OffsetDateTime, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "change")] | ||
#[serde(rename = "change",)] | ||
pub change: Change, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Change { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "signature")] | ||
#[serde(rename = "signature",)] | ||
pub signature: String, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] | ||
pub artifact_id: Option<String>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "repository", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] | ||
pub repository: Option<Repository>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Repository { | ||
#[serde(rename = "id")] | ||
#[serde(rename = "id",)] | ||
pub id: String, | ||
#[serde(rename = "source", skip_serializing_if = "Option::is_none")] | ||
pub source: Option<String>, | ||
#[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] | ||
pub source: Option<fluent_uri::Uri<String>>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "name", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] | ||
pub name: Option<String>, | ||
#[serde(rename = "url", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] | ||
pub url: Option<String>, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// code generated by cdevents/sdk-rust/generator (subject.hbs) | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Content { | ||
#[serde(rename = "name", skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] | ||
pub name: Option<String>, | ||
} | ||
|
Oops, something went wrong.