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 djc committed Sep 8, 2022
1 parent 339d6fb commit 5305023
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 @@ -207,6 +191,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 @@ -271,7 +257,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 @@ -398,7 +384,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 @@ -458,6 +444,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 @@ -520,7 +508,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 @@ -648,7 +636,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 @@ -708,6 +696,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 @@ -767,7 +757,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 @@ -908,7 +898,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 @@ -968,6 +958,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 @@ -1024,7 +1016,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 5305023

Please sign in to comment.