Skip to content

Commit

Permalink
📝 update typo, remove commented code, move comments,... apply review …
Browse files Browse the repository at this point in the history
…suggestion

Signed-off-by: David Bernard <david.bernard.31@gmail.com>
  • Loading branch information
davidB committed Jan 23, 2024
1 parent 0439319 commit 6c9ccc9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 83 deletions.
12 changes: 0 additions & 12 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ indent_size = 2
#inside code block, indentation could be anything
indent_size = unset

[*.py]
indent_size = 4
# 88 is the default for black formatter
# 79 is PEP8's recommendation
# 119 is django's recommendation
max_line_length = 88

[*.rs]
# https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md
indent_size = 4
Expand All @@ -33,11 +26,6 @@ max_line_length = 200
[{*.bazel,*.bzl,BUILD,WORKSPACE}]
indent_size = 4

[*.java]
# try to align with https://github.com/diffplug/spotless (https://github.com/google/google-java-format)
indent_size = 4
max_line_length = 100

# The JSON files contain newlines inconsistently
[*.json]
insert_final_newline = unset
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ members = ["cdevents-sdk", "generator"]
[workspace.package]
edition = "2021"
version = "0.1.0"
authors = ["David Bernard"]
authors = [
# The actual list of contributors can be retrieved from the git log
"The CDEvents Rust SDK Authors",
]
license = "ASL-2.0"
repository = "https://github.com/cdevents/sdk-rust"
rust-version = "1.75"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ If you would like to contribute, see our [development](DEVELOPMENT.md) guide.

- [CDEvents](https://cdevents.dev)
- [CDEvents Primer](https://cdevents.dev/docs/primer/)
- [CDFoundation Specification](https://cdevents.dev/docs/)
- [CDEvents Specification](https://cdevents.dev/docs/)
4 changes: 1 addition & 3 deletions cdevents-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ publish = true

[dependencies]
cloudevents-sdk = { version = "0.7", optional = true, default-features = false }
fluent-uri = "0.1" # support uri & uri-reference, preserve the original string, but young, doesn't impl PartialEq,...
# http = "1" # doesn't support uri-reference
# http-serde = "2"
fluent-uri = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
Expand Down
63 changes: 0 additions & 63 deletions cdevents-sdk/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,69 +26,6 @@ pub(crate) mod datetime {
}
}

// pub(crate) fn ok_or_none<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
// where
// D: Deserializer<'de>,
// T: Deserialize<'de>,
// {
// let v = Value::deserialize(deserializer)?;
// Ok(T::deserialize(v).ok())
// }

// pub(crate) mod ok_or_none {
// use serde::{Deserialize, Deserializer, Serializer};

// pub fn deserialize<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
// where
// D: Deserializer<'de>,
// T: Deserialize<'de>,
// {
// let v = Option::deserialize(deserializer)?;
// Ok(T::deserialize(v).ok())
// }

// pub fn serialize<S>(
// input: &Option<fluent_uri::Uri<String>>,
// serializer: S,
// ) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// match input {
// None => serializer.serialize_none(),
// Some(input) => crate::serde::uri_reference::serialize(input, serializer),
// }
// }
// }

// pub(crate) mod uri_reference_optional {
// use serde::{Deserialize, Deserializer, Serializer};

// #[derive(Deserialize)]
// struct Wrapper(#[serde(with = "crate::serde::uri_reference")] fluent_uri::Uri<String>);

// pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<fluent_uri::Uri<String>>, D::Error>
// where
// D: Deserializer<'de>,
// {
// let v = Option::deserialize(deserializer)?;
// Ok(v.map(|Wrapper(a)| a))
// }

// pub fn serialize<S>(
// input: &Option<fluent_uri::Uri<String>>,
// serializer: S,
// ) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// match input {
// None => serializer.serialize_none(),
// Some(input) => crate::serde::uri_reference::serialize(input, serializer),
// }
// }
// }

pub(crate) mod fluent_uri {
use serde::{de::Error, Deserialize, Deserializer, Serializer};

Expand Down
5 changes: 4 additions & 1 deletion cdevents-sdk/src/uri.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// wrapper for fluent_uri::Uri to allow for restristed set of operations
// and to complete currently missing features.
//TODO impl the check difference for URI and Uri
// Why fluent_uri?
// - support uri & uri-reference, preserve the original string, but young, doesn't impl PartialEq,...
// - http::Uri, more mature, but doesn't support uri-reference, and normalize url when generate string
//TODO impl the check difference for Uri and Uri-reference

use std::str::FromStr;

Expand Down
4 changes: 2 additions & 2 deletions generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Goals: generate rust code for cdevents from jsonschema provided as part of cdeve

## Why not use a jsonschema to rust generator?

- I tried some (like ) and they failed (no error), maybe too early, not support for the version of jsonschema used by cdevents (often they support jsonschema draft-4)
- The json schema (v0.3) are not connected, so lot of duplication (context,...), so classical generator will create as many Context type as Event type,...
- I tried some and they failed (no error), maybe too early, not support for the version of jsonschema used by cdevents (often they support jsonschema draft-4)
- The json schema (v0.3) are not connected, so lot of duplication (context,...), so classical generators will create as many Context type as Event type,... Our implementation only part of the schema is extracted to generate what is different aka the `content` of subjects.

## Run

Expand Down

0 comments on commit 6c9ccc9

Please sign in to comment.