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 36a6e0d commit 733aa10
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 117 deletions.
55 changes: 25 additions & 30 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

//! ISO 8601 date and time with time zone.
use crate::oldtime::Duration as OldDuration;
use core::cmp::Ordering;
use core::ops::{Add, Sub};
use core::{fmt, hash, str};
#[cfg(any(feature = "std", test))]
use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::string::{String, ToString};
#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::ops::{Add, Sub};
use core::{fmt, hash, str};
#[cfg(feature = "std")]
use std::string::ToString;
#[cfg(any(feature = "std", test))]
use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(any(feature = "alloc", feature = "std", test))]
use crate::format::DelayedFormat;
Expand All @@ -25,10 +28,9 @@ use crate::naive::{self, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
#[cfg(feature = "clock")]
use crate::offset::Local;
use crate::offset::{FixedOffset, Offset, TimeZone, Utc};
use crate::oldtime::Duration as OldDuration;
use crate::Date;
use crate::{Datelike, Timelike, Weekday};
#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;

/// Specific formatting options for seconds. This may be extended in the
/// future, so exhaustive matching in external code is not recommended.
Expand Down Expand Up @@ -1214,9 +1216,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 +1379,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 +1532,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 +1688,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 +1840,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 +1995,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 +2144,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 +2312,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 +2455,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
Loading

0 comments on commit 733aa10

Please sign in to comment.