Skip to content

Commit

Permalink
refactor: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Oct 22, 2024
1 parent a85d78c commit f7aed55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,23 @@ pub enum Offset {
}

impl Offset {
pub fn value_millis(&self) -> i128 {
#[cfg(feature = "ser")]
pub(crate) fn as_millis(&self) -> i128 {
match self {
Self::Pos(dur) => dur.as_millis() as i128,
Self::Neg(dur) => -(dur.as_millis() as i128),
}
}

#[cfg(feature = "ser")]
pub fn serialize_offset<S>(offset: &Option<Self>, serializer: S) -> Result<S::Ok, S::Error>
pub(crate) fn serialize_offset<S>(
offset: &Option<Self>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let value = offset.as_ref().map(|o| o.value_millis()).unwrap_or(0);
let value = offset.as_ref().map(|o| o.as_millis()).unwrap_or(0);
serializer.serialize_i128(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Function {
}

#[cfg(feature = "ser")]
pub fn serialize_variadic<S>(variadic: &bool, serializer: S) -> Result<S::Ok, S::Error>
pub(crate) fn serialize_variadic<S>(variadic: &bool, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand Down
7 changes: 5 additions & 2 deletions src/util/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn display_duration(duration: &Duration) -> String {
}

#[cfg(feature = "ser")]
pub fn serialize_duration<S>(dur: &Duration, serializer: S) -> Result<S::Ok, S::Error>
pub(crate) fn serialize_duration<S>(dur: &Duration, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand All @@ -145,7 +145,10 @@ where
}

#[cfg(feature = "ser")]
pub fn serialize_duration_opt<S>(dur: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error>
pub(crate) fn serialize_duration_opt<S>(
dur: &Option<Duration>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand Down

0 comments on commit f7aed55

Please sign in to comment.