-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #109
- Loading branch information
Showing
33 changed files
with
578 additions
and
110 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
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
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,27 @@ | ||
pub(crate) fn generate( | ||
mut writer: impl std::io::Write, | ||
vis: &str, | ||
type_name: &str, | ||
inner_type_name: &str, | ||
datetime_serialization_format: super::DateTimeSerializationFormat, | ||
map_namespace: &impl crate::MapNamespace, | ||
) -> Result<(), crate::Error> { | ||
let local = crate::map_namespace_local_to_string(map_namespace)?; | ||
|
||
let serialize_format = match datetime_serialization_format { | ||
super::DateTimeSerializationFormat::SixDecimalDigits => "RFC3339_SUBSECONDS_SIX", | ||
super::DateTimeSerializationFormat::ZeroDecimalDigits => "RFC3339_SUBSECONDS_ZERO", | ||
}; | ||
|
||
writeln!( | ||
writer, | ||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/newtype_time.rs")), | ||
local = local, | ||
type_name = type_name, | ||
vis = vis, | ||
inner_type_name = inner_type_name, | ||
serialize_format = serialize_format, | ||
)?; | ||
|
||
Ok(()) | ||
} |
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,43 @@ | ||
struct {type_name}({vis}{inner_type_name}); | ||
|
||
impl<'de> {local}serde::Deserialize<'de> for {type_name} {{ | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: {local}serde::Deserializer<'de> {{ | ||
struct Visitor; | ||
|
||
impl<'de> {local}serde::de::Visitor<'de> for Visitor {{ | ||
type Value = {type_name}; | ||
|
||
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {{ | ||
f.write_str({type_name:?}) | ||
}} | ||
|
||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error> where D: {local}serde::Deserializer<'de> {{ | ||
struct Visitor; | ||
|
||
impl<'de> {local}serde::de::Visitor<'de> for Visitor {{ | ||
type Value = {local}time::OffsetDateTime; | ||
|
||
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {{ | ||
f.write_str("OffsetDateTime") | ||
}} | ||
|
||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E> where E: {local}serde::de::Error {{ | ||
{local}time::OffsetDateTime::parse(s, &{local}time::format_description::well_known::Rfc3339).map_err(serde::de::Error::custom) | ||
}} | ||
}} | ||
|
||
Ok({type_name}(deserializer.deserialize_str(Visitor)?)) | ||
}} | ||
}} | ||
|
||
deserializer.deserialize_newtype_struct({type_name:?}, Visitor) | ||
}} | ||
}} | ||
|
||
impl {local}serde::Serialize for {type_name} {{ | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: {local}serde::Serializer {{ | ||
// TODO: This could be `&self.0.format({local}time2::{serialize_format})`, | ||
// but can't because of https://github.com/time-rs/time/issues/359 | ||
serializer.serialize_newtype_struct({type_name:?}, &self.0.format(&{local}time2::{serialize_format}).map_err({local}serde::ser::Error::custom)?) | ||
}} | ||
}} |
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
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
Oops, something went wrong.