diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..328007c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*.sw? +Cargo.lock +target/ diff --git a/Cargo.toml b/Cargo.toml index 378caf7..3e0c1ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ description = "a femtosecond-based representation of time, duration, and frequen authors = ["transistor fet "] license = "MIT OR Apache-2.0" repository = "https://github.com/transistorfet/femtos" +readme = "README.md" [dependencies] diff --git a/README.md b/README.md index 27fbbba..a086b5d 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,5 @@ # `femtos` -> A femtosecond representation of time, duration, and frequency +> A femtosecond-based representation of time, duration, and frequency, for the purpose of simulation diff --git a/src/lib.rs b/src/lib.rs index 17fda66..6504f96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,9 +10,9 @@ use core::ops::{Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div, DivAssign}; /// In webassembly, using u128 results in exceedingly slow runtimes, so we use u64 instead /// which is enough for 5 hours of simulation time. #[cfg(not(target_arch = "wasm32"))] -type Femtos = u128; +pub type Femtos = u128; #[cfg(target_arch = "wasm32")] -type Femtos = u64; +pub type Femtos = u64; /// Represents a duration of time in femtoseconds /// @@ -254,10 +254,10 @@ impl Duration { /// # Examples /// /// ``` - /// use femtos::Duration; + /// use femtos::{Duration, Femtos}; /// - /// assert_eq!(Duration::from_secs(1).checked_add(Duration::from_secs(1)), Some(Duration::from_secs(2))) - /// assert_eq!(Duration::from_secs(1).checked_add(Duration::from_femtos(Femtos::MAX)), None) + /// assert_eq!(Duration::from_secs(1).checked_add(Duration::from_secs(1)), Some(Duration::from_secs(2))); + /// assert_eq!(Duration::from_secs(1).checked_add(Duration::from_femtos(Femtos::MAX)), None); /// ``` #[inline] pub const fn checked_add(self, rhs: Self) -> Option { @@ -275,8 +275,8 @@ impl Duration { /// ``` /// use femtos::Duration; /// - /// assert_eq!(Duration::from_secs(1).checked_sub(Duration::from_secs(1)), Some(Duration::ZERO)) - /// assert_eq!(Duration::from_secs(1).checked_sub(Duration::from_femtos(2), None) + /// assert_eq!(Duration::from_secs(1).checked_sub(Duration::from_secs(1)), Some(Duration::ZERO)); + /// assert_eq!(Duration::from_femtos(1).checked_sub(Duration::from_femtos(2)), None); /// ``` #[inline] pub const fn checked_sub(self, rhs: Self) -> Option { @@ -406,10 +406,13 @@ impl Instant { /// # Examples /// /// ``` - /// use femtos::Instant; + /// use femtos::{Instant, Duration, Femtos}; /// - /// assert_eq!(Instant::START.checked_add(Duration::from_secs(1)).as_duration(), Some(Duration::from_secs(1))) - /// assert_eq!(Instant::START.checked_add(Duration::from_femtos(Femtos::MAX)).as_duration(), None) + /// assert_eq!( + /// Instant::START.checked_add(Duration::from_secs(1)).map(|i| i.as_duration()), + /// Some(Duration::from_secs(1)) + /// ); + /// assert_eq!(Instant::FOREVER.checked_add(Duration::from_femtos(1)), None); /// ``` #[inline] pub const fn checked_add(self, duration: Duration) -> Option { @@ -425,10 +428,13 @@ impl Instant { /// # Examples /// /// ``` - /// use femtos::Instant; + /// use femtos::{Instant, Duration, Femtos}; /// - /// assert_eq!(Instant::FOREVER.checked_sub(Duration::from_secs(1)).as_duration(), Some(Duration::from_femtos(Femtos::MAX - 1))) - /// assert_eq!(Instant::START.checked_sub(Duration::from_secs(1)).as_duration(), None) + /// assert_eq!( + /// Instant::FOREVER.checked_sub(Duration::from_femtos(1)).map(|i| i.as_duration()), + /// Some(Duration::from_femtos(Femtos::MAX - 1)) + /// ); + /// assert_eq!(Instant::START.checked_sub(Duration::from_secs(1)), None); /// ``` #[inline] pub const fn checked_sub(self, duration: Duration) -> Option { @@ -536,7 +542,7 @@ impl Frequency { /// # Examples /// /// ``` - /// use femtos::Frequency; + /// use femtos::{Duration, Frequency}; /// /// assert_eq!(Frequency::from_hz(1).period_duration(), Duration::from_secs(1)); /// ```