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