Skip to content

Commit

Permalink
Implement Serde support for SystemTime
Browse files Browse the repository at this point in the history
Co-Authored-By: Léo Gaspard <[email protected]>
Co-Authored-By: Fedeparma74 <[email protected]>
  • Loading branch information
3 people committed Feb 28, 2024
1 parent 5f49b76 commit 5673adf
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .config/topic.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
18
20
1G
1M
1ns
Expand All @@ -11,6 +11,8 @@ io
JS
MDN
MSRV
Serde
Serde's
timestamps
v1
Versioning
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Run Rustdoc
env:
RUSTDOCFLAGS: --crate-version main --cfg=docsrs
run: cargo doc --no-deps -Z rustdoc-map -Z rustdoc-scrape-examples --target wasm32-unknown-unknown
run: cargo doc --no-deps -Z rustdoc-map -Z rustdoc-scrape-examples --target wasm32-unknown-unknown --all-features
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Fix permissions
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ jobs:
- wasm32-unknown-unknown
rust:
- { version: stable, component: "", rustflags: "", args: "" }
- { version: nightly, component: ",rust-src", flags: "-Ctarget-feature=+atomics,+bulk-memory", args: "-Zbuild-std=panic_abort,std" }
features:
- { features: "" }
- { features: --all-features }
include:
- target: wasm32-unknown-unknown
rust: { version: nightly, component: ",rust-src", flags: "-Ctarget-feature=+atomics,+bulk-memory", args: "-Zbuild-std=panic_abort,std" }
- target: x86_64-unknown-linux-gnu
rust: { version: stable, component: "", rustflags: "", args: "" }
features: { features: "" }

steps:
- name: Checkout
Expand All @@ -40,8 +45,8 @@ jobs:
- name: Run Clippy
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo clippy --all-targets --target ${{ matrix.target }} ${{ matrix.rust.args }} -- -D warnings
run: cargo clippy --all-targets ${{ matrix.features.features }} --target ${{ matrix.target }} ${{ matrix.rust.args }} -- -D warnings
- name: Run Rustdoc
env:
RUSTDOCFLAGS: -D warnings ${{ matrix.rust.flags }}
run: cargo doc --no-deps --document-private-items --target ${{ matrix.target }} ${{ matrix.rust.args }}
run: cargo doc --no-deps --document-private-items ${{ matrix.features.features }} --target ${{ matrix.target }} ${{ matrix.rust.args }}
37 changes: 23 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-latest
rust:
- { version: "1.60", msrv: true, component: "", flags: "", args: "" }
- { version: stable, msrv: false, component: "", flags: "", args: "" }
- { version: nightly, msrv: false, component: --component rust-src, flags: "-Ctarget-feature=+atomics,+bulk-memory", args: "-Zbuild-std=panic_abort,std" }
target:
- { target: x86_64-unknown-linux-gnu, native: true }
- { target: wasm32-unknown-unknown, native: false }
features:
- { features: "" }
- { features: --all-features }
include:
- os: macos-latest
rust: { version: stable, msrv: false, component: "", flags: "", args: "" }
target: { target: wasm32-unknown-unknown, native: false }
- os: ubuntu-latest
rust: { version: nightly, msrv: false, component: --component rust-src, flags: "-Ctarget-feature=+atomics,+bulk-memory", args: "-Zbuild-std=panic_abort,std" }
target: { target: wasm32-unknown-unknown, native: false }
rust: { version: "1.60", msrv: true, component: "", flags: "", args: "" }
target: { target: x86_64-unknown-linux-gnu, native: true }
features: { features: "" }
- os: ubuntu-latest
rust: { version: stable, msrv: false, component: "", flags: "", args: "" }
target: { target: x86_64-unknown-linux-gnu, native: true }
features: { features: "" }
exclude:
- os: macos-latest
rust: { version: nightly, msrv: false, component: --component rust-src, flags: "-Ctarget-feature=+atomics,+bulk-memory", args: "-Zbuild-std=panic_abort,std" }
target: { target: wasm32-unknown-unknown, native: false }
rust: { version: "1.60", msrv: true, component: "", flags: "", args: "" }

steps:
- name: Checkout
Expand All @@ -58,13 +64,13 @@ jobs:
- name: Build
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo build --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
run: cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
- name: Documentation
if: matrix.os == 'ubuntu-latest'
env:
RUSTDOCFLAGS: ${{ matrix.rust.flags }}
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo doc --no-deps --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
run: cargo doc --no-deps ${{ matrix.features.features }} --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
- name: Test
if: matrix.rust.msrv == false && matrix.os == 'ubuntu-latest' && matrix.target.native == true
run: cargo test --all-targets --no-fail-fast
Expand All @@ -73,19 +79,19 @@ jobs:
env:
CHROMEDRIVER: chromedriver
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo test --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
run: cargo test ${{ matrix.features.features }} --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
- name: Test on Firefox
if: matrix.rust.msrv == false && matrix.os == 'ubuntu-latest' && matrix.target.native == false
env:
GECKODRIVER: geckodriver
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo test --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
run: cargo test ${{ matrix.features.features }} --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
- name: Test on Safari
if: matrix.rust.msrv == false && matrix.os == 'macos-latest'
env:
SAFARIDRIVER: safaridriver
RUSTFLAGS: ${{ matrix.rust.flags }}
run: cargo test --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
run: cargo test ${{ matrix.features.features }} --all-targets --no-fail-fast --target ${{ matrix.target.target }} ${{ matrix.rust.args }}
- name: Documentation Test
if: matrix.rust.msrv == false && matrix.target.native == true && matrix.os == 'ubuntu-latest'
run: cargo test --doc --no-fail-fast
Expand All @@ -107,6 +113,9 @@ jobs:
target:
- x86_64-unknown-linux-gnu
- wasm32-unknown-unknown
features:
- { features: "" }
- { features: --all-features }

steps:
- name: Checkout
Expand All @@ -120,4 +129,4 @@ jobs:
- name: Build
run: |
cargo +nightly update -Z minimal-versions
cargo build --target ${{ matrix.target }}
cargo build ${{ matrix.features.features }} --target ${{ matrix.target }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Introduced a `serde` feature with de-serialization support for
`SystemTime`.


## [1.0.0] - 2024-01-14

### Added
Expand Down
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ repository = "https://github.com/daxpedda/web-time"
rust-version = "1.60"
version = "1.0.0"

[features]
serde = ["dep:serde"]

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
js-sys = "0.3.20"
serde = { version = "1", optional = true }
wasm-bindgen = { version = "0.2.70", default-features = false }

[dev-dependencies]
Expand All @@ -24,6 +28,7 @@ pollster = { version = "0.3", features = ["macro"] }
[target.'cfg(target_family = "wasm")'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"
serde_json = "1"
wasm-bindgen-futures = "0.4"
wasm-bindgen-test = "0.3"
web-sys = { version = "0.3", features = [
Expand All @@ -50,7 +55,13 @@ lto = true
name = "benchmark"
path = "benches/benchmark.rs"

[[test]]
name = "serde"
path = "tests/serde.rs"
required-features = ["serde"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg=docsrs"]
targets = ["wasm32-unknown-unknown"]

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ let now = Instant::now();
let time = SystemTime::now();
```

## Features

### `serde`

Implements [`serde::Deserialize`] and [`serde::Serialize`] for
[`SystemTime`].

## MSRV

As this library heavily relies on [`wasm-bindgen`] the MSRV depends on it.
Expand Down Expand Up @@ -123,4 +130,6 @@ conditions.
[`performance.now()`]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
[`Performance.timeOrigin`]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/timeOrigin
[`Performance` object]: https://developer.mozilla.org/en-US/docs/Web/API/performance_property
[`serde::Deserialize`]: https://docs.rs/serde/1/serde/trait.Deserialize.html
[`serde::Serialize`]: https://docs.rs/serde/1/serde/trait.Serialize.html
[`wasm-bindgen`]: https://crates.io/crates/wasm-bindgen
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
//! let time = SystemTime::now();
//! ```
//!
//! # Features
//!
//! ## `serde`
//!
//! Implements [`serde::Deserialize`] and [`serde::Serialize`] for
//! [`SystemTime`].
//!
//! # MSRV
//!
//! As this library heavily relies on [`wasm-bindgen`] the MSRV depends on it.
Expand Down Expand Up @@ -115,6 +122,11 @@
//! [`performance.now()`]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
//! [`Performance.timeOrigin`]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/timeOrigin
//! [`Performance` object]: https://developer.mozilla.org/en-US/docs/Web/API/performance_property
#![cfg_attr(
any(not(feature = "serde"), not(target_family = "wasm")),
doc = "[`serde::Deserialize`]: https://docs.rs/serde/1/serde/trait.Deserialize.html",
doc = "[`serde::Serialize`]: https://docs.rs/serde/1/serde/trait.Serialize.html"
)]
//! [`wasm-bindgen`]: https://crates.io/crates/wasm-bindgen
#![cfg_attr(docsrs, feature(doc_cfg))]
Expand Down
2 changes: 2 additions & 0 deletions src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod instant;
mod js;
#[cfg(feature = "serde")]
mod serde;
mod system_time;

pub use std::time::*;
Expand Down
Loading

0 comments on commit 5673adf

Please sign in to comment.