Make serde optional
This commit is contained in:
parent
c0def257fb
commit
a440e730fa
@ -4,6 +4,8 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[features]
|
||||||
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
month::Month, weekday::Weekday, year::Year, zone::TimeZone, SECONDS_PER_DAY,
|
month::Month, weekday::Weekday, year::Year, zone::TimeZone, SECONDS_PER_DAY,
|
||||||
SECONDS_PER_HOUR, SECONDS_PER_MINUTE,
|
SECONDS_PER_HOUR, SECONDS_PER_MINUTE,
|
||||||
},
|
},
|
||||||
serde::{Deserialize, Serialize},
|
|
||||||
std::{cmp, fmt},
|
std::{cmp, fmt},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct DateTime {
|
pub struct DateTime {
|
||||||
pub year: Year,
|
pub year: Year,
|
||||||
pub month: Month,
|
pub month: Month,
|
||||||
|
@ -8,6 +8,7 @@ pub(crate) mod year;
|
|||||||
pub(crate) mod zone;
|
pub(crate) mod zone;
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
pub use datetime::DateTime;
|
||||||
|
|
||||||
pub static SECONDS_PER_MINUTE: i64 = 60;
|
pub static SECONDS_PER_MINUTE: i64 = 60;
|
||||||
pub static SECONDS_PER_HOUR: i64 = 60 * 60;
|
pub static SECONDS_PER_HOUR: i64 = 60 * 60;
|
||||||
|
11
src/month.rs
11
src/month.rs
@ -1,12 +1,13 @@
|
|||||||
use std::str::FromStr;
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{year::Year, SECONDS_PER_DAY},
|
crate::{year::Year, SECONDS_PER_DAY},
|
||||||
serde::{Deserialize, Serialize},
|
std::{cmp, error, fmt, str},
|
||||||
std::{cmp, error, fmt},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Month {
|
pub enum Month {
|
||||||
Janurary = 1,
|
Janurary = 1,
|
||||||
@ -138,7 +139,7 @@ impl fmt::Display for Month {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Month {
|
impl str::FromStr for Month {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
pub use crate::{
|
pub use crate::{
|
||||||
datetime::DateTime,
|
|
||||||
month::{Error as MonthError, Month},
|
month::{Error as MonthError, Month},
|
||||||
weekday::Weekday,
|
weekday::Weekday,
|
||||||
year::Year,
|
year::Year,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use std::fmt;
|
#[cfg(feature = "serde")]
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Weekday {
|
pub enum Weekday {
|
||||||
Thursday,
|
Thursday,
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::SECONDS_PER_DAY,
|
crate::SECONDS_PER_DAY,
|
||||||
serde::{Deserialize, Serialize},
|
|
||||||
std::{cmp, fmt, num::ParseIntError, str::FromStr},
|
std::{cmp, fmt, num::ParseIntError, str::FromStr},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub enum Year {
|
pub enum Year {
|
||||||
Normal(i32),
|
Normal(i32),
|
||||||
Leap(i32),
|
Leap(i32),
|
||||||
|
10
src/zone.rs
10
src/zone.rs
@ -1,10 +1,13 @@
|
|||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::SECONDS_PER_HOUR,
|
crate::SECONDS_PER_HOUR,
|
||||||
serde::{Deserialize, Serialize},
|
|
||||||
std::{error, fmt, str::FromStr},
|
std::{error, fmt, str::FromStr},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub enum Sign {
|
pub enum Sign {
|
||||||
Positive,
|
Positive,
|
||||||
Negative,
|
Negative,
|
||||||
@ -23,7 +26,8 @@ impl fmt::Display for Sign {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub enum TimeZone {
|
pub enum TimeZone {
|
||||||
Offset { sign: Sign, hours: u8, minutes: u8 },
|
Offset { sign: Sign, hours: u8, minutes: u8 },
|
||||||
Utc,
|
Utc,
|
||||||
|
Loading…
Reference in New Issue
Block a user