Skip to content

Commit

Permalink
Merge pull request #77 from mattico/serde
Browse files Browse the repository at this point in the history
Add serde support to concrete units
  • Loading branch information
PTaylor-us authored Apr 28, 2021
2 parents 068d1d9 + c2b1700 commit fd63640
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --lib
args: --lib --all-features

- name: Test Library
uses: actions-rs/cargo@v1
with:
command: test
args: --lib -- --test-threads=1
args: --lib --all-features -- --test-threads=1

- name: Test Documentation
uses: actions-rs/cargo@v1
with:
command: test
args: --doc
args: --doc --all-features

- name: Clippy
uses: actions-rs/cargo@v1
Expand All @@ -60,6 +60,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: doc
args: --all-features

- name: Build examples
uses: marcopolo/cargo@master
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/FluenTech/embedded-time/"
license = "MIT OR Apache-2.0"
exclude = ["/.github/"]
autoexamples = false
resolver = "2"
# The examples must be their own package due to conflicts with the criterion crate.

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -24,6 +25,7 @@ members = ["examples"]

[dependencies]
num = { version = "0.3.0", default-features = false }
serde = { version = "1.0.0", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
crossbeam-utils = "0.7.2"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ Hertz::<u64>::try_from(Generic::new(2_000_u32, Fraction::new(1,1_000))) == Ok(He
- Thorough documentation with examples
- Example for the nRF52_DK board

## Features

- `serde`: Enables `serde::Deserialize` and `serde::Serialize` implementations for concrete units.

## Notes
Some parts of this crate were derived from various sources:
- [`RTIC`](https://github.com/rtic-rs/cortex-m-rtic)
Expand Down
1 change: 1 addition & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ pub mod units {
( $name:ident, ($numer:expr, $denom:expr) ) => {
/// A duration unit type
#[derive(Copy, Clone, Eq, Ord, Hash, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct $name<T: TimeInt = u32>(pub T);

impl<T: TimeInt> $name<T> {
Expand Down
1 change: 1 addition & 0 deletions src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use num::traits::{WrappingAdd, WrappingSub};
/// Instant::<SomeClock>::new(23);
/// ```
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Instant<Clock: crate::Clock> {
ticks: Clock::T,
}
Expand Down
1 change: 1 addition & 0 deletions src/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ pub mod units {
( $name:ident, ($numer:expr, $denom:expr), $desc:literal ) => {
#[doc = $desc]
#[derive(Copy, Clone, Eq, Ord, Hash, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct $name<T: TimeInt = u32>(pub T);

impl<T: TimeInt> $name<T> {
Expand Down

0 comments on commit fd63640

Please sign in to comment.