Added serde as an optional dependency

This commit is contained in:
Nicola Belluti 2024-05-05 21:55:52 +02:00
parent 6f0d2587b4
commit e2d1f141d6
3 changed files with 30 additions and 0 deletions

22
Cargo.lock generated
View File

@ -50,6 +50,7 @@ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"num-traits", "num-traits",
"serde",
"windows-targets", "windows-targets",
] ]
@ -141,6 +142,27 @@ name = "r701"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde",
]
[[package]]
name = "serde"
version = "1.0.200"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.200"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb"
dependencies = [
"proc-macro2",
"quote",
"syn",
] ]
[[package]] [[package]]

View File

@ -7,3 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
chrono = { version = "0.4.38", default-features = false, features = ["clock"] } chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
serde = { version = "1.0.200", default-features = false, features = ["derive"], optional = true }
[features]
serde = ["chrono/serde", "dep:serde"]

View File

@ -1,6 +1,9 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Local, TimeZone}; use chrono::{DateTime, Local, TimeZone};
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Clock { pub enum Clock {
#[default] #[default]
FirstIn, FirstIn,
@ -13,6 +16,7 @@ unsafe impl Send for Clock {}
unsafe impl Sync for Clock {} unsafe impl Sync for Clock {}
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Record { pub struct Record {
pub employee_id: u32, pub employee_id: u32,
pub clock: Clock, pub clock: Clock,