Skip to main content

datex_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![feature(assert_matches)]
3#![feature(gen_blocks)]
4#![feature(async_iterator)]
5#![feature(type_alias_impl_trait)]
6#![feature(trait_alias)]
7#![feature(box_patterns)]
8#![feature(if_let_guard)]
9#![feature(try_trait_v2)]
10// #![allow(unused_parens)]
11#![feature(associated_type_defaults)]
12#![feature(core_float_math)]
13#![feature(thread_local)]
14#![feature(future_join)]
15#![allow(static_mut_refs)]
16
17extern crate alloc;
18extern crate num_integer;
19
20#[cfg(feature = "std")]
21extern crate std;
22
23pub mod channel;
24pub mod dif;
25pub mod prelude;
26
27#[cfg(feature = "ast")]
28pub mod ast;
29#[cfg(feature = "compiler")]
30pub mod compiler;
31#[cfg(feature = "decompiler")]
32pub mod decompiler;
33#[cfg(feature = "compiler")]
34pub mod fmt;
35pub mod global;
36pub mod libs;
37#[cfg(all(feature = "lsp", feature = "std"))]
38pub mod lsp;
39pub mod network;
40#[cfg(feature = "parser")]
41pub mod parser;
42pub mod runtime;
43pub mod shared_values;
44#[cfg(feature = "compiler")]
45pub mod type_inference;
46#[cfg(feature = "compiler")]
47pub mod visitor;
48
49pub mod core_compiler;
50pub mod dxb_parser;
51#[cfg(all(feature = "macro_utils", feature = "std", feature = "compiler"))]
52pub mod macro_utils;
53pub mod serde;
54mod stub;
55pub mod task;
56pub mod traits;
57pub mod types;
58pub mod utils;
59pub mod values;
60
61// reexport macros
62pub use datex_macros_internal as macros;
63extern crate core;
64
65// HashMap and HashSet that work in both std and no_std environments.
66pub mod collections {
67    #[cfg(feature = "std")]
68    pub use std::collections::{HashMap, HashSet, hash_map, hash_set};
69
70    #[cfg(not(feature = "std"))]
71    pub use hashbrown::{HashMap, HashSet, hash_map, hash_set};
72}
73
74/// Reexport of Mutex that works in both std and no_std environments.
75pub mod std_sync {
76    #[cfg(not(feature = "std"))]
77    pub use spin::Mutex;
78    #[cfg(feature = "std")]
79    pub use std::sync::Mutex;
80}
81
82/// Crypto implementations selection based on target architecture and features.
83pub mod crypto {
84    cfg_if::cfg_if! {
85        if #[cfg(any(feature = "target_native", test))] {
86            pub use datex_crypto_native::CryptoNative as CryptoImpl;
87        } else if #[cfg(feature = "target_esp32")] {
88            pub use datex_crypto_esp32::CryptoEsp32 as CryptoImpl;
89        } else if #[cfg(feature = "target_wasm")] {
90            pub use datex_crypto_web::CryptoWeb as CryptoImpl;
91        } else {
92            pub use crate::stub::crypto::CryptoStub as CryptoImpl;
93        }
94    }
95}
96
97pub mod time {
98
99    mod system_time {
100        cfg_if::cfg_if! {
101            if #[cfg(feature = "target_wasm")] {
102                pub use web_time::{SystemTime, UNIX_EPOCH};
103            } else if #[cfg(feature = "target_native")] {
104                pub use std::time::{SystemTime, UNIX_EPOCH};
105            }
106        }
107    }
108
109    cfg_if::cfg_if! {
110        if #[cfg(feature = "target_wasm")] {
111            pub use web_time::{Instant};
112        } else if #[cfg(feature = "std")] {
113            pub use std::time::{Instant};
114        } else if #[cfg(feature = "embassy_runtime")] {
115            pub use embassy_time::{Instant};
116        } else {
117            pub use crate::stub::time::{Instant};
118        }
119    }
120
121    // current unix timestamp in milliseconds
122    pub fn now_ms() -> u64 {
123        cfg_if::cfg_if! {
124            if #[cfg(any(feature = "target_wasm", feature = "target_native"))] {
125                use system_time::{SystemTime, UNIX_EPOCH};
126                SystemTime::now()
127                    .duration_since(UNIX_EPOCH)
128                    .expect("System time is before UNIX_EPOCH")
129                    .as_millis() as u64
130            } else if #[cfg(feature = "target_esp32")] {
131                datex_crypto_esp32::now_ms()
132            } else {
133                Instant::now().elapsed().as_millis() as u64
134            }
135        }
136    }
137}
138
139pub mod random {
140    #[cfg(not(feature = "std"))]
141    pub use foldhash::fast::RandomState;
142    #[cfg(feature = "std")]
143    pub use std::hash::RandomState;
144}