Skip to content

Commit

Permalink
Move the datetime::serde timestamp visitors into the respective mod…
Browse files Browse the repository at this point in the history
…ules

The internal structs can be moved into their respective modules
because `pub(super)` is now supported by the MSRV.
  • Loading branch information
nickelc authored and pitdicker committed May 16, 2023
1 parent 8c76475 commit fe9315a
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ use crate::naive::datetime::serde::serde_from;
use crate::offset::Local;
use crate::offset::{FixedOffset, TimeZone, Utc};

#[doc(hidden)]
#[derive(Debug)]
pub struct SecondsTimestampVisitor;

#[doc(hidden)]
#[derive(Debug)]
pub struct NanoSecondsTimestampVisitor;

#[doc(hidden)]
#[derive(Debug)]
pub struct MicroSecondsTimestampVisitor;

#[doc(hidden)]
#[derive(Debug)]
pub struct MilliSecondsTimestampVisitor;

/// Serialize into a rfc3339 time string
///
/// See [the `serde` module](./serde/index.html) for alternate
Expand Down Expand Up @@ -149,7 +133,7 @@ pub mod ts_nanoseconds {
use crate::offset::TimeZone;
use crate::{DateTime, Utc};

use super::{serde_from, NanoSecondsTimestampVisitor};
use super::serde_from;

/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch
///
Expand Down Expand Up @@ -209,6 +193,8 @@ pub mod ts_nanoseconds {
d.deserialize_i64(NanoSecondsTimestampVisitor)
}

pub(super) struct NanoSecondsTimestampVisitor;

impl<'de> de::Visitor<'de> for NanoSecondsTimestampVisitor {
type Value = DateTime<Utc>;

Expand Down Expand Up @@ -273,7 +259,7 @@ pub mod ts_nanoseconds_option {

use crate::{DateTime, Utc};

use super::NanoSecondsTimestampVisitor;
use super::ts_nanoseconds::NanoSecondsTimestampVisitor;

/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch or none
///
Expand Down Expand Up @@ -402,7 +388,7 @@ pub mod ts_microseconds {
use core::fmt;
use serde::{de, ser};

use super::{serde_from, MicroSecondsTimestampVisitor};
use super::serde_from;
use crate::offset::TimeZone;
use crate::{DateTime, Utc};

Expand Down Expand Up @@ -464,6 +450,8 @@ pub mod ts_microseconds {
d.deserialize_i64(MicroSecondsTimestampVisitor)
}

pub(super) struct MicroSecondsTimestampVisitor;

impl<'de> de::Visitor<'de> for MicroSecondsTimestampVisitor {
type Value = DateTime<Utc>;

Expand Down Expand Up @@ -526,7 +514,7 @@ pub mod ts_microseconds_option {
use core::fmt;
use serde::{de, ser};

use super::MicroSecondsTimestampVisitor;
use super::ts_microseconds::MicroSecondsTimestampVisitor;
use crate::{DateTime, Utc};

/// Serialize a UTC datetime into an integer number of microseconds since the epoch or none
Expand Down Expand Up @@ -656,7 +644,7 @@ pub mod ts_milliseconds {
use core::fmt;
use serde::{de, ser};

use super::{serde_from, MilliSecondsTimestampVisitor};
use super::serde_from;
use crate::offset::TimeZone;
use crate::{DateTime, Utc};

Expand Down Expand Up @@ -718,6 +706,8 @@ pub mod ts_milliseconds {
d.deserialize_i64(MilliSecondsTimestampVisitor).map(|dt| dt.with_timezone(&Utc))
}

pub(super) struct MilliSecondsTimestampVisitor;

impl<'de> de::Visitor<'de> for MilliSecondsTimestampVisitor {
type Value = DateTime<Utc>;

Expand Down Expand Up @@ -777,7 +767,7 @@ pub mod ts_milliseconds_option {
use core::fmt;
use serde::{de, ser};

use super::MilliSecondsTimestampVisitor;
use super::ts_milliseconds::MilliSecondsTimestampVisitor;
use crate::{DateTime, Utc};

/// Serialize a UTC datetime into an integer number of milliseconds since the epoch or none
Expand Down Expand Up @@ -920,7 +910,7 @@ pub mod ts_seconds {
use core::fmt;
use serde::{de, ser};

use super::{serde_from, SecondsTimestampVisitor};
use super::serde_from;
use crate::offset::TimeZone;
use crate::{DateTime, Utc};

Expand Down Expand Up @@ -982,6 +972,8 @@ pub mod ts_seconds {
d.deserialize_i64(SecondsTimestampVisitor)
}

pub(super) struct SecondsTimestampVisitor;

impl<'de> de::Visitor<'de> for SecondsTimestampVisitor {
type Value = DateTime<Utc>;

Expand Down Expand Up @@ -1038,7 +1030,7 @@ pub mod ts_seconds_option {
use core::fmt;
use serde::{de, ser};

use super::SecondsTimestampVisitor;
use super::ts_seconds::SecondsTimestampVisitor;
use crate::{DateTime, Utc};

/// Serialize a UTC datetime into an integer number of seconds since the epoch or none
Expand Down

0 comments on commit fe9315a

Please sign in to comment.