diff --git a/README.md b/README.md index 1693942..3da24fa 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,8 @@ # mock_instant **_NOTE_** As of version 0.5. MockClock/Instant/SystemTime have been moved to specific modules -**_NOTE_** The modules, `global` and `thread_local` change the behavior across threads. If `global` is used, the clock keeps its state across threads, otherwise if `thread_local` is used, a new _source_ is made for each thread - -## Migration from older versions - -Simply import the types from the correct namespace: - -`mock_instant::global` - -and -`mock_instant::thread_local` - ---- +**_NOTE_** The modules, `global` and `thread_local` change the behavior across threads. If `global` is used, the clock keeps its state across threads, otherwise if `thread_local` is used, a new _source_ is made for each thread To ensure unsurprising behavior, **reset** the clock _before_ each test (if that behavior is applicable.) @@ -55,7 +44,7 @@ MockClock::advance(Duration::from_secs(2)); assert_eq!(now.elapsed(), Duration::from_secs(17)); ``` -### API: +## API: ```rust,compile_fail // Overrides the current time to this `Duration` @@ -82,7 +71,7 @@ Instant::now().is_thread_local() -> bool SystemTime::now().is_thread_local() -> bool ``` -### Usage: +## Usage: **_NOTE_** The clock starts at `Duration::ZERO` @@ -94,16 +83,21 @@ You can also get the current frozen time with `MockClock::time` `SystemTime` is also mockable with a similar API. -### Thread-safety: +## Thread-safety: Two modes are provided via modules. The APIs are identical but the `MockClock` source has different behavior in different threads. -- global +- `mock_instant::global` -when using mock_instant::global `MockClock` `Instant` and `SystemTime` will share its state across threads + - `MockClock` will have a new state per thread + - `Instant`will have a new state per thread + - `SystemTime` will have a new state per thread -- thread_local +- `mock_instant::thread_local` + - `MockClock` will have a new state per thread + - `Instant`will have a new state per thread + - `SystemTime` will have a new state per thread -when using mock_instant::thread_local `MockClock` `Instant` and `SystemTime` will have a new state per thread +--- License: 0BSD diff --git a/src/lib.rs b/src/lib.rs index 87b3f9a..08bb68b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ /*! # mock_instant **_NOTE_** As of version 0.5. MockClock/Instant/SystemTime have been moved to specific modules + **_NOTE_** The modules, `global` and `thread_local` change the behavior across threads. If `global` is used, the clock keeps its state across threads, otherwise if `thread_local` is used, a new *source* is made for each thread To ensure unsurprising behavior, **reset** the clock _before_ each test (if that behavior is applicable.) @@ -85,13 +86,15 @@ You can also get the current frozen time with `MockClock::time` Two modes are provided via modules. The APIs are identical but the `MockClock` source has different behavior in different threads. -- global - -when using mock_instant::global `MockClock` `Instant` and `SystemTime` will share its state across threads - -- thread_local +- `mock_instant::global` + - `MockClock` will have a new state per thread + - `Instant`will have a new state per thread + - `SystemTime` will have a new state per thread -when using mock_instant::thread_local `MockClock` `Instant` and `SystemTime` will have a new state per thread +- `mock_instant::thread_local` + - `MockClock` will have a new state per thread + - `Instant`will have a new state per thread + - `SystemTime` will have a new state per thread */ diff --git a/src/thread_local.rs b/src/thread_local.rs index 2c307e2..2c41721 100644 --- a/src/thread_local.rs +++ b/src/thread_local.rs @@ -35,7 +35,7 @@ crate::macros::define_instant! { crate::macros::define_system_time! { MockClock::system_time; true; - /// This uses a global mutex for its time source + /// This uses a thread-local cell for its time source } crate::macros::define_instant_tests!();