Make serde optional

This commit is contained in:
Nathan Fisher 2024-01-30 20:47:11 -05:00
parent c0def257fb
commit a440e730fa
8 changed files with 32 additions and 17 deletions

View File

@ -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 }

View File

@ -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,

View File

@ -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;

View File

@ -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> {

View File

@ -1,5 +1,4 @@
pub use crate::{
datetime::DateTime,
month::{Error as MonthError, Month},
weekday::Weekday,
year::Year,

View File

@ -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,

View File

@ -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),

View File

@ -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,