Skip to content

Commit

Permalink
Get rid of most extern crate statements
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Mar 22, 2022
1 parent c30dfbf commit b8b4694
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 109 deletions.
37 changes: 15 additions & 22 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,9 @@ pub(super) mod serde {
#[cfg(feature = "clock")]
use crate::offset::Local;
use crate::offset::{FixedOffset, LocalResult, TimeZone, Utc};
use crate::serdelib::{de, ser};
use crate::{ne_timestamp, SerdeError};
use core::fmt;
use serde::{de, ser};

#[doc(hidden)]
#[derive(Debug)]
Expand Down Expand Up @@ -1377,7 +1377,7 @@ pub(super) mod serde {
/// ```
pub mod ts_nanoseconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

use crate::offset::TimeZone;
use crate::{DateTime, Utc};
Expand Down Expand Up @@ -1530,7 +1530,7 @@ pub(super) mod serde {
/// ```
pub mod ts_nanoseconds_option {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

use crate::{DateTime, Utc};

Expand Down Expand Up @@ -1686,14 +1686,12 @@ pub(super) mod serde {
/// ```
pub mod ts_microseconds {
use core::fmt;
use serde::{de, ser};

use serdelib::{de, ser};

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

use super::{serde_from, MicroSecondsTimestampVisitor};

/// Serialize a UTC datetime into an integer number of microseconds since the epoch
///
/// Intended for use with `serde`s `serialize_with` attribute.
Expand Down Expand Up @@ -1840,11 +1838,10 @@ pub(super) mod serde {
/// ```
pub mod ts_microseconds_option {
use core::fmt;
use serdelib::{de, ser};

use crate::{DateTime, Utc};
use serde::{de, ser};

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

/// Serialize a UTC datetime into an integer number of microseconds since the epoch or none
///
Expand Down Expand Up @@ -1996,13 +1993,12 @@ pub(super) mod serde {
/// ```
pub mod ts_milliseconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

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

use super::{serde_from, MilliSecondsTimestampVisitor};

/// Serialize a UTC datetime into an integer number of milliseconds since the epoch
///
/// Intended for use with `serde`s `serialize_with` attribute.
Expand Down Expand Up @@ -2146,11 +2142,10 @@ pub(super) mod serde {
/// ```
pub mod ts_milliseconds_option {
use core::fmt;
use serdelib::{de, ser};

use crate::{DateTime, Utc};
use serde::{de, ser};

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

/// Serialize a UTC datetime into an integer number of milliseconds since the epoch or none
///
Expand Down Expand Up @@ -2315,13 +2310,12 @@ pub(super) mod serde {
/// ```
pub mod ts_seconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

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

use super::{serde_from, SecondsTimestampVisitor};

/// Serialize a UTC datetime into an integer number of seconds since the epoch
///
/// Intended for use with `serde`s `serialize_with` attribute.
Expand Down Expand Up @@ -2459,11 +2453,10 @@ pub(super) mod serde {
/// ```
pub mod ts_seconds_option {
use core::fmt;
use serdelib::{de, ser};

use crate::{DateTime, Utc};
use serde::{de, ser};

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

/// Serialize a UTC datetime into an integer number of seconds since the epoch or none
///
Expand Down
4 changes: 4 additions & 0 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

#![allow(ellipsis_inclusive_range_patterns)]

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -466,6 +469,7 @@ fn format_inner<'a>(
};

use core::fmt::Write;
use num_integer::{div_floor, mod_floor};

match *item {
Item::Literal(s) | Item::Space(s) => result.push_str(s),
Expand Down
41 changes: 6 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,56 +451,27 @@
manual_range_contains,
))]

#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(all(feature = "std", not(feature = "alloc")))]
extern crate std as alloc;
#[cfg(any(feature = "std", test))]
extern crate std as core;

#[cfg(feature = "oldtime")]
extern crate time as oldtime;
#[cfg(not(feature = "oldtime"))]
mod oldtime;
// this reexport is to aid the transition and should not be in the prelude!
pub use oldtime::Duration;

#[cfg(feature = "clock")]
extern crate libc;
#[cfg(all(feature = "clock", windows))]
extern crate winapi;
#[cfg(all(
feature = "clock",
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
))]
mod sys;

extern crate num_integer;
extern crate num_traits;
#[cfg(feature = "rustc-serialize")]
extern crate rustc_serialize;
#[cfg(feature = "serde")]
extern crate serde as serdelib;
#[cfg(feature = "__doctest")]
#[cfg_attr(feature = "__doctest", cfg(doctest))]
#[macro_use]
extern crate doc_comment;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate js_sys;
#[cfg(feature = "unstable-locales")]
extern crate pure_rust_locales;
#[cfg(feature = "bench")]
extern crate test;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate wasm_bindgen;
use doc_comment::doctest;

#[cfg(feature = "__doctest")]
#[cfg_attr(feature = "__doctest", cfg(doctest))]
doctest!("../README.md");

use core::fmt;

// this reexport is to aid the transition and should not be in the prelude!
pub use oldtime::Duration;

pub use date::{Date, MAX_DATE, MIN_DATE};
#[cfg(feature = "rustc-serialize")]
pub use datetime::rustc_serialize::TsSeconds;
Expand Down Expand Up @@ -578,6 +549,9 @@ pub mod serde {

// Until rust 1.18 there is no "pub(crate)" so to share this we need it in the root

#[cfg(feature = "serde")]
use core::fmt;

#[cfg(feature = "serde")]
enum SerdeError<V: fmt::Display, D: fmt::Display> {
NonExistent { timestamp: V },
Expand Down Expand Up @@ -623,9 +597,6 @@ pub use month::{Month, ParseMonthError};
mod traits;
pub use traits::{Datelike, Timelike};

#[cfg(test)]
extern crate num_iter;

mod test {
#[allow(unused_imports)]
use super::*;
Expand Down
9 changes: 3 additions & 6 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl fmt::Debug for ParseMonthError {
#[cfg(feature = "serde")]
mod month_serde {
use super::Month;
use serdelib::{de, ser};
use serde::{de, ser};

use core::fmt;

Expand Down Expand Up @@ -240,12 +240,9 @@ mod month_serde {
}
}

#[cfg(test)]
extern crate serde_json;

#[test]
fn test_serde_serialize() {
use self::serde_json::to_string;
use serde_json::to_string;
use Month::*;

let cases: Vec<(Month, &str)> = vec![
Expand All @@ -271,7 +268,7 @@ mod month_serde {

#[test]
fn test_serde_deserialize() {
use self::serde_json::from_str;
use serde_json::from_str;
use Month::*;

let cases: Vec<(&str, Month)> = vec![
Expand Down
13 changes: 4 additions & 9 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ mod rustc_serialize {
mod serde {
use super::NaiveDate;
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

// TODO not very optimized for space (binary formats would want something better)

Expand Down Expand Up @@ -1873,26 +1873,21 @@ mod serde {
}
}

#[cfg(test)]
extern crate bincode;
#[cfg(test)]
extern crate serde_json;

#[test]
fn test_serde_serialize() {
super::test_encodable_json(self::serde_json::to_string);
super::test_encodable_json(serde_json::to_string);
}

#[test]
fn test_serde_deserialize() {
super::test_decodable_json(|input| self::serde_json::from_str(&input));
super::test_decodable_json(|input| serde_json::from_str(&input));
}

#[test]
fn test_serde_bincode() {
// Bincode is relevant to test separately from JSON because
// it is not self-describing.
use self::bincode::{deserialize, serialize, Infinite};
use bincode::{deserialize, serialize, Infinite};

let d = NaiveDate::from_ymd(2014, 7, 24);
let encoded = serialize(&d, Infinite).unwrap();
Expand Down
31 changes: 14 additions & 17 deletions src/naive/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

//! ISO 8601 date and time without timezone.

use crate::oldtime::Duration as OldDuration;
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;
use core::ops::{Add, AddAssign, Sub, SubAssign};
use core::{fmt, hash, str};

use num_integer::div_mod_floor;
use num_traits::ToPrimitive;

Expand All @@ -18,6 +21,7 @@ use crate::format::{Fixed, Item, Numeric, Pad};
use crate::naive::date::{MAX_DATE, MIN_DATE};
use crate::naive::time::{MAX_TIME, MIN_TIME};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::oldtime::Duration as OldDuration;
use crate::{Datelike, Timelike, Weekday};

/// The tight upper bound guarantees that a duration with `|Duration| >= 2^MAX_SECS_BITS`
Expand Down Expand Up @@ -1720,7 +1724,7 @@ pub(super) mod rustc_serialize {
pub(super) mod serde {
use super::NaiveDateTime;
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

/// Serialize a `NaiveDateTime` as an RFC 3339 string
///
Expand Down Expand Up @@ -1808,7 +1812,7 @@ pub(super) mod serde {
/// ```
pub mod ts_nanoseconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

use crate::{ne_timestamp, NaiveDateTime};

Expand Down Expand Up @@ -1960,7 +1964,7 @@ pub(super) mod serde {
/// ```
pub mod ts_milliseconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

use crate::{ne_timestamp, NaiveDateTime};

Expand Down Expand Up @@ -2109,7 +2113,7 @@ pub(super) mod serde {
/// ```
pub mod ts_seconds {
use core::fmt;
use serdelib::{de, ser};
use serde::{de, ser};

use crate::{ne_timestamp, NaiveDateTime};

Expand Down Expand Up @@ -2218,29 +2222,22 @@ pub(super) mod serde {
}
}

#[cfg(test)]
extern crate bincode;
#[cfg(test)]
extern crate serde_derive;
#[cfg(test)]
extern crate serde_json;

#[test]
fn test_serde_serialize() {
super::test_encodable_json(self::serde_json::to_string);
super::test_encodable_json(serde_json::to_string);
}

#[test]
fn test_serde_deserialize() {
super::test_decodable_json(|input| self::serde_json::from_str(&input));
super::test_decodable_json(|input| serde_json::from_str(&input));
}

// Bincode is relevant to test separately from JSON because
// it is not self-describing.
#[test]
fn test_serde_bincode() {
use self::bincode::{deserialize, serialize, Infinite};
use crate::naive::NaiveDate;
use bincode::{deserialize, serialize, Infinite};

let dt = NaiveDate::from_ymd(2016, 7, 8).and_hms_milli(9, 10, 48, 90);
let encoded = serialize(&dt, Infinite).unwrap();
Expand All @@ -2250,10 +2247,10 @@ pub(super) mod serde {

#[test]
fn test_serde_bincode_optional() {
use self::bincode::{deserialize, serialize, Infinite};
use self::serde_derive::{Deserialize, Serialize};
use crate::prelude::*;
use crate::serde::ts_nanoseconds_option;
use bincode::{deserialize, serialize, Infinite};
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Test {
Expand Down

0 comments on commit b8b4694

Please sign in to comment.