1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2022 houseme
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Time source abstraction supporting both `std` and `no_std` environments.
use Timestamp;
/// Get current time in milliseconds since Unix epoch (std version).
pub
// --- no_std time source ---
use ;
/// Global time source for no_std environments.
///
/// Must be set via [`set_time_source`] before generating IDs.
static NO_STD_TIME_SOURCE: AtomicI64 = new;
/// Get current time in milliseconds (no_std version).
///
/// Returns the value last set via [`set_time_source`].
pub
/// Set the time source for no_std environments.
///
/// Must be called periodically (e.g., from a timer interrupt or RTC read)
/// with the current time in milliseconds since Unix epoch.
///
/// # Example
///
/// ```rust,ignore
/// // In a timer interrupt handler or main loop:
/// snowflake_me::set_time_source(get_rtc_millis());
/// ```