1#![doc = include_str!("../doc-src/root-docs.md")]
2#![allow(clippy::needless_doctest_main)]
3#![no_std]
5
6pub mod prelude {
9 #[cfg(all(feature = "rmx-rustlib-core", not(feature = "rmx-rustlib-std")))]
14 pub use ::core::prelude::rust_2021::*;
15
16 #[cfg(feature = "rmx-rustlib-std")]
17 pub use ::std::prelude::rust_2021::*;
18
19 #[cfg(feature = "rmx-rustlib-alloc")]
22 pub use ::alloc::{format, vec};
23
24 #[cfg(feature = "rmx-rustlib-alloc")]
25 pub use crate::extras::fmt;
26
27 #[cfg(feature = "rmx-rustlib-core")]
35 pub use ::core::cmp::Ordering;
36
37 #[cfg(feature = "futures")]
40 pub use ::futures::prelude::*;
41
42 #[cfg(feature = "anyhow")]
45 pub use ::anyhow::{Context as _, anyhow, bail};
46
47 #[cfg(feature = "anyhow")]
48 pub use crate::extras::{A, AnyError, AnyResult};
49
50 #[cfg(feature = "cfg-if")]
51 pub use ::cfg_if::cfg_if;
52
53 #[cfg(feature = "extension-trait")]
54 pub use ::extension_trait::extension_trait;
55
56 #[cfg(feature = "log")]
57 pub use ::log::{debug, error, info, trace, warn};
58
59 #[cfg(all(feature = "futures", feature = "rmx-feature-default"))]
60 pub use ::futures::{executor::block_on, future::Either};
61
62 #[cfg(feature = "itertools")]
63 pub use ::itertools::Itertools as _;
64
65 pub use crate::extras::default;
68
69 #[cfg(feature = "rmx-rustlib-core")]
70 pub use crate::bug;
71
72 #[cfg(feature = "rmx-rustlib-alloc")]
73 pub use crate::extras::S;
74
75 #[cfg(feature = "rmx-rustlib-alloc")]
76 pub use crate::extras::O;
77
78 #[cfg(all(feature = "extension-trait", feature = "anyhow"))]
79 pub use crate::extras::AnyResultExpect as _;
80 #[cfg(feature = "extension-trait")]
81 pub use crate::extras::OptionExpect as _;
82 #[cfg(feature = "extension-trait")]
83 pub use crate::extras::QuickClone as _;
84 #[cfg(feature = "extension-trait")]
85 pub use crate::extras::QuickToOwned as _;
86 #[cfg(feature = "extension-trait")]
87 pub use crate::extras::QuickToString as _;
88 #[cfg(feature = "extension-trait")]
89 pub use crate::extras::RangeExt as _;
90 #[cfg(feature = "extension-trait")]
91 pub use crate::extras::ResultExpect as _;
92 #[cfg(feature = "extension-trait")]
93 pub use crate::extras::ResultIgnore as _;
94}
95
96pub mod extras {
97 #[cfg(feature = "rmx-rustlib-core")]
101 #[macro_export]
102 macro_rules! bug {
103 () => {
104 core::panic!("unexpected case (bug!)")
105 };
106 ($($arg:tt)+) => {
107 core::panic!("unexpected case (bug!): {}", $crate::format_args!($($arg)+))
108 };
109 }
110
111 #[cfg(feature = "anyhow")]
112 pub use ::anyhow::{Error as AnyError, Result as AnyResult, anyhow as A};
113
114 #[cfg(feature = "rmx-rustlib-alloc")]
115 pub use ::alloc::format as fmt;
116
117 pub fn default<T: Default>() -> T {
118 Default::default()
119 }
120
121 pub fn init() {
122 #[cfg(feature = "env_logger")]
123 fn maybe_init_env_logger() {
124 crate::env_logger::Builder::new()
125 .filter_level(log::LevelFilter::Info)
126 .format_timestamp(None)
127 .parse_default_env()
128 .init();
129 }
130 #[cfg(not(feature = "env_logger"))]
131 fn maybe_init_env_logger() {}
132
133 maybe_init_env_logger();
134 }
135
136 pub fn init_crate_name(crate_name: &str) {
137 #[cfg(feature = "env_logger")]
138 fn maybe_init_env_logger(crate_name: &str) {
139 crate::env_logger::Builder::new()
140 .filter_module(crate_name, log::LevelFilter::Info)
141 .format_timestamp(None)
142 .parse_default_env()
143 .init();
144 }
145 #[cfg(not(feature = "env_logger"))]
146 fn maybe_init_env_logger(_crate_name: &str) {}
147
148 maybe_init_env_logger(crate_name);
149 }
150
151 pub fn recurse<F, R>(f: F) -> R
152 where
153 F: FnOnce() -> R,
154 {
155 f()
157 }
158
159 #[cfg(feature = "rmx-rustlib-alloc")]
160 #[allow(non_snake_case)]
161 pub fn S<T>(s: &T) -> crate::alloc::string::String
162 where
163 T: crate::alloc::string::ToString + ?Sized,
164 {
165 crate::alloc::string::ToString::to_string(s)
166 }
167
168 #[cfg(feature = "rmx-rustlib-alloc")]
169 #[allow(non_snake_case)]
170 pub fn O<T>(o: &T) -> T::Owned
171 where
172 T: crate::alloc::borrow::ToOwned + ?Sized,
173 {
174 crate::alloc::borrow::ToOwned::to_owned(o)
175 }
176
177 #[cfg(feature = "extension-trait")]
178 #[extension_trait::extension_trait]
179 pub impl<T> QuickToString for T
180 where
181 T: crate::alloc::string::ToString + ?Sized,
182 {
183 #[allow(non_snake_case)]
184 fn S(&self) -> crate::alloc::string::String {
185 crate::alloc::string::ToString::to_string(self)
186 }
187 }
188
189 #[cfg(feature = "extension-trait")]
190 #[extension_trait::extension_trait]
191 pub impl<T> QuickToOwned for T
192 where
193 T: crate::alloc::borrow::ToOwned,
194 {
195 type Owned = T::Owned;
196
197 #[allow(non_snake_case)]
198 fn O(&self) -> Self::Owned {
199 crate::alloc::borrow::ToOwned::to_owned(self)
200 }
201 }
202
203 #[cfg(feature = "extension-trait")]
204 #[extension_trait::extension_trait]
205 pub impl<T> QuickClone<T> for T
206 where
207 T: Clone,
208 {
209 #[allow(non_snake_case)]
210 fn C(&self) -> T {
211 self.clone()
212 }
213 }
214
215 #[cfg(feature = "extension-trait")]
216 #[extension_trait::extension_trait]
217 pub impl<T> OptionExpect<T> for Option<T> {
218 #[track_caller]
219 #[allow(non_snake_case)]
220 fn X(self) -> T {
221 match self {
222 Some(v) => v,
223 None => panic!("impossible `None` option"),
224 }
225 }
226 }
227
228 #[cfg(feature = "extension-trait")]
229 #[extension_trait::extension_trait]
230 pub impl<T, E> ResultExpect<T, E> for Result<T, E>
231 where
232 E: core::error::Error,
233 {
234 #[track_caller]
235 #[allow(non_snake_case)]
236 fn X(self) -> T {
237 match self {
238 Ok(v) => v,
239 Err(e) => panic!("impossible `Err` result: {e}"),
240 }
241 }
242 }
243
244 #[cfg(all(feature = "extension-trait", feature = "anyhow"))]
245 #[extension_trait::extension_trait]
246 pub impl<T> AnyResultExpect<T> for AnyResult<T> {
247 #[track_caller]
248 #[allow(non_snake_case)]
249 fn X(self) -> T {
250 match self {
251 Ok(v) => v,
252 Err(e) => panic!("impossible `Err` result: {e}"),
253 }
254 }
255 }
256
257 #[cfg(feature = "extension-trait")]
262 #[extension_trait::extension_trait]
263 pub impl<T, E> ResultIgnore<T, E> for Result<T, E> {
264 #[track_caller]
265 #[allow(non_snake_case)]
266 fn I(self) {
267 let _ = self;
268 }
269 }
270
271 #[cfg(feature = "extension-trait")]
274 #[extension_trait::extension_trait]
275 pub impl RangeExt for core::ops::Range<usize> {
276 fn from_start_len(start: usize, len: usize) -> Option<core::ops::Range<usize>> {
277 Some(start..start.checked_add(len)?)
278 }
279
280 fn subrange(&self, sub: core::ops::Range<usize>) -> Option<core::ops::Range<usize>> {
281 if sub.start >= self.len() || sub.end > self.len() {
282 return None;
283 }
284 let new_start = self.start.checked_add(sub.start);
285 let new_end = self.start.checked_add(sub.end);
286 match (new_start, new_end) {
287 (Some(new_start), Some(new_end)) => Some(new_start..new_end),
288 _ => None,
289 }
290 }
291
292 fn checked_sub(&self, other: usize) -> Option<core::ops::Range<usize>> {
293 let new_start = self.start.checked_sub(other);
294 let new_end = self.end.checked_sub(other);
295 match (new_start, new_end) {
296 (Some(new_start), Some(new_end)) => Some(new_start..new_end),
297 _ => None,
298 }
299 }
300 }
301}
302
303#[cfg(feature = "rmx-rustlib-core")]
306#[doc(inline)]
307pub extern crate core;
308
309#[cfg(feature = "rmx-rustlib-alloc")]
310#[doc(inline)]
311pub extern crate alloc;
312
313#[cfg(feature = "rmx-rustlib-std")]
314#[doc(inline)]
315pub extern crate std;
316
317#[cfg(feature = "rmx-rustlib-proc_macro")]
318#[doc(inline)]
319pub extern crate proc_macro;
320
321#[cfg(feature = "ahash")]
324pub mod ahash {
325 #![doc = include_str!("../doc-src/crate-ahash.md")]
326
327 pub use ::ahash::*;
328}
329
330#[cfg(feature = "anyhow")]
331pub mod anyhow {
332 #![doc = include_str!("../doc-src/crate-anyhow.md")]
333
334 pub use ::anyhow::*;
335}
336
337#[cfg(feature = "axum")]
338pub mod axum {
339 pub use ::axum::*;
344}
345
346#[cfg(feature = "backtrace")]
347pub mod backtrace {
348 pub use ::backtrace::*;
353}
354
355#[cfg(feature = "base64")]
356pub mod base64 {
357 pub use ::base64::*;
362}
363
364#[cfg(feature = "bindgen")]
365pub mod bindgen {
366 pub use ::bindgen::*;
371}
372
373#[cfg(feature = "bitflags")]
374pub mod bitflags {
375 #![doc = include_str!("../doc-src/crate-bitflags.md")]
376
377 pub use ::bitflags::*;
378}
379
380#[cfg(feature = "blake3")]
381pub mod blake3 {
382 pub use ::blake3::*;
387}
388
389#[cfg(feature = "byteorder")]
390pub mod byteorder {
391 pub use ::byteorder::*;
396}
397
398#[cfg(feature = "bytes")]
399pub mod bytes {
400 pub use ::bytes::*;
405}
406
407#[cfg(feature = "cc")]
408pub mod cc {
409 pub use ::cc::*;
414}
415
416#[cfg(feature = "cfg-if")]
417pub mod cfg_if {
418 pub use ::cfg_if::*;
423}
424
425#[cfg(feature = "chrono")]
426pub mod chrono {
427 pub use ::chrono::*;
432}
433
434#[cfg(feature = "clap")]
435pub mod clap {
436 pub use ::clap::*;
441}
442
443#[cfg(feature = "ctrlc")]
444pub mod ctrlc {
445 pub use ::ctrlc::*;
450}
451
452#[cfg(feature = "crossbeam")]
453pub mod crossbeam {
454 pub use ::crossbeam::*;
459}
460
461#[cfg(feature = "cxx")]
462pub mod cxx {
463 pub use ::cxx::*;
468}
469
470#[cfg(feature = "cxx-build")]
471pub mod cxx_build {
472 pub use ::cxx::*;
477}
478
479#[cfg(feature = "derive_more")]
480pub mod derive_more {
481 pub use ::derive_more::*;
486}
487
488#[cfg(feature = "env_logger")]
489pub mod env_logger {
490 pub use ::env_logger::*;
495}
496
497#[cfg(feature = "extension-trait")]
498pub mod extension_trait {
499 pub use ::extension_trait::*;
504}
505
506#[cfg(feature = "futures")]
507pub mod futures {
508 pub use ::futures::*;
513}
514
515#[cfg(feature = "hex")]
516pub mod hex {
517 pub use ::hex::*;
522}
523
524#[cfg(feature = "http")]
525pub mod http {
526 pub use ::http::*;
531}
532
533#[cfg(feature = "hyper")]
534pub mod hyper {
535 pub use ::hyper::*;
540}
541
542#[cfg(feature = "itertools")]
543pub mod itertools {
544 pub use ::itertools::*;
549}
550
551#[cfg(feature = "jiff")]
552pub mod jiff {
553 pub use ::jiff::*;
558}
559
560#[cfg(feature = "json5")]
561pub mod json5 {
562 pub use ::json5::*;
567}
568
569#[cfg(feature = "libc")]
570pub mod libc {
571 pub use ::libc::*;
576}
577
578#[cfg(feature = "log")]
579pub mod log {
580 pub use ::log::*;
585}
586
587#[cfg(feature = "mime")]
588pub mod mime {
589 pub use ::mime::*;
594}
595
596#[cfg(feature = "nom")]
597pub mod nom {
598 pub use ::nom::*;
603}
604
605#[cfg(feature = "num-bigint")]
606pub mod num_bigint {
607 pub use ::num_bigint::*;
612}
613
614#[cfg(feature = "num_cpus")]
615pub mod num_cpus {
616 pub use ::num_cpus::*;
621}
622
623#[cfg(feature = "num_enum")]
624pub mod num_enum {
625 pub use ::num_enum::*;
630}
631
632#[cfg(feature = "proc-macro2")]
633pub mod proc_macro2 {
634 pub use ::proc_macro2::*;
639}
640
641#[cfg(feature = "proptest")]
642pub mod proptest {
643 pub use ::proptest::*;
648}
649
650#[cfg(feature = "quote")]
651pub mod quote {
652 pub use ::quote::*;
657}
658
659#[cfg(feature = "rand")]
660pub mod rand {
661 pub use ::rand::*;
666}
667
668#[cfg(feature = "rand_chacha")]
669pub mod rand_chacha {
670 pub use ::rand_chacha::*;
675}
676
677#[cfg(feature = "rand_pcg")]
678pub mod rand_pcg {
679 pub use ::rand_pcg::*;
684}
685
686#[cfg(feature = "rayon")]
687pub mod rayon {
688 pub use ::rayon::*;
693}
694
695#[cfg(feature = "regex")]
696pub mod regex {
697 pub use ::regex::*;
702}
703
704#[cfg(feature = "reqwest")]
705pub mod reqwest {
706 pub use ::reqwest::*;
711}
712
713#[cfg(feature = "rustyline")]
714pub mod rustyline {
715 pub use ::rustyline::*;
720}
721
722#[cfg(feature = "semver")]
723pub mod semver {
724 pub use ::semver::*;
729}
730
731#[cfg(feature = "serde")]
732pub mod serde {
733 pub use ::serde::*;
738}
739
740#[cfg(feature = "serde_json")]
741pub mod serde_json {
742 pub use ::serde_json::*;
747}
748
749#[cfg(feature = "sha2")]
750pub mod sha2 {
751 pub use ::sha2::*;
756}
757
758#[cfg(feature = "socket2")]
759pub mod socket2 {
760 pub use ::socket2::*;
765}
766
767#[cfg(feature = "static_assertions")]
768pub mod static_assertions {
769 pub use ::static_assertions::*;
774}
775
776#[cfg(feature = "syn")]
777pub mod syn {
778 pub use ::syn::*;
783}
784
785#[cfg(feature = "tempfile")]
786pub mod tempfile {
787 pub use ::tempfile::*;
792}
793
794#[cfg(feature = "tera")]
795pub mod tera {
796 pub use ::tera::*;
801}
802
803#[cfg(feature = "termcolor")]
804pub mod termcolor {
805 pub use ::termcolor::*;
810}
811
812#[cfg(feature = "thiserror")]
813pub mod thiserror {
814 pub use ::thiserror::*;
819}
820
821#[cfg(feature = "tokio")]
822pub mod tokio {
823 pub use ::tokio::*;
828}
829
830#[cfg(feature = "tower")]
831pub mod tower {
832 pub use ::tower::*;
838}
839
840#[cfg(feature = "toml")]
841pub mod toml {
842 pub use ::toml::*;
847}
848
849#[cfg(feature = "unicode-segmentation")]
850pub mod unicode_segmentation {
851 pub use ::unicode_segmentation::*;
856}
857
858#[cfg(feature = "url")]
859pub mod url {
860 pub use ::url::*;
865}
866
867#[cfg(feature = "walkdir")]
868pub mod walkdir {
869 pub use ::walkdir::*;
874}
875
876#[cfg(feature = "xshell")]
877pub mod xshell {
878 pub use ::xshell::*;
883}