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 #[cfg(feature = "rmx-rustlib-std")]
303 pub fn copy_dir_recursive(
304 src: &crate::std::path::Path,
305 dst: &crate::std::path::Path,
306 ) -> crate::std::io::Result<()> {
307 crate::std::fs::create_dir_all(dst)?;
308
309 for entry in crate::std::fs::read_dir(src)? {
310 let entry = entry?;
311 let file_type = entry.file_type()?;
312 let src_path = entry.path();
313 let dst_path = dst.join(entry.file_name());
314
315 if file_type.is_dir() {
316 copy_dir_recursive(&src_path, &dst_path)?;
317 } else {
318 crate::std::fs::copy(&src_path, &dst_path)?;
319 }
320 }
321
322 Ok(())
323 }
324}
325
326#[cfg(feature = "rmx-rustlib-core")]
329#[doc(inline)]
330pub extern crate core;
331
332#[cfg(feature = "rmx-rustlib-alloc")]
333#[doc(inline)]
334pub extern crate alloc;
335
336#[cfg(feature = "rmx-rustlib-std")]
337#[doc(inline)]
338pub extern crate std;
339
340#[cfg(feature = "rmx-rustlib-proc_macro")]
341#[doc(inline)]
342pub extern crate proc_macro;
343
344#[cfg(feature = "ahash")]
347pub mod ahash {
348 #![doc = include_str!("../doc-src/crate-ahash.md")]
349
350 pub use ::ahash::*;
351}
352
353#[cfg(feature = "anyhow")]
354pub mod anyhow {
355 #![doc = include_str!("../doc-src/crate-anyhow.md")]
356
357 pub use ::anyhow::*;
358}
359
360#[cfg(feature = "axum")]
361pub mod axum {
362 pub use ::axum::*;
367}
368
369#[cfg(feature = "backtrace")]
370pub mod backtrace {
371 pub use ::backtrace::*;
376}
377
378#[cfg(feature = "base64")]
379pub mod base64 {
380 pub use ::base64::*;
385}
386
387#[cfg(feature = "bindgen")]
388pub mod bindgen {
389 pub use ::bindgen::*;
394}
395
396#[cfg(feature = "bitflags")]
397pub mod bitflags {
398 #![doc = include_str!("../doc-src/crate-bitflags.md")]
399
400 pub use ::bitflags::*;
401}
402
403#[cfg(feature = "blake3")]
404pub mod blake3 {
405 pub use ::blake3::*;
410}
411
412#[cfg(feature = "byteorder")]
413pub mod byteorder {
414 pub use ::byteorder::*;
419}
420
421#[cfg(feature = "bytes")]
422pub mod bytes {
423 pub use ::bytes::*;
428}
429
430#[cfg(feature = "cc")]
431pub mod cc {
432 pub use ::cc::*;
437}
438
439#[cfg(feature = "cfg-if")]
440pub mod cfg_if {
441 pub use ::cfg_if::*;
446}
447
448#[cfg(feature = "chrono")]
449pub mod chrono {
450 pub use ::chrono::*;
455}
456
457#[cfg(feature = "clap")]
458pub mod clap {
459 pub use ::clap::*;
464}
465
466#[cfg(feature = "ctrlc")]
467pub mod ctrlc {
468 pub use ::ctrlc::*;
473}
474
475#[cfg(feature = "crossbeam")]
476pub mod crossbeam {
477 pub use ::crossbeam::*;
482}
483
484#[cfg(feature = "cxx")]
485pub mod cxx {
486 pub use ::cxx::*;
491}
492
493#[cfg(feature = "cxx-build")]
494pub mod cxx_build {
495 pub use ::cxx::*;
500}
501
502#[cfg(feature = "derive_more")]
503pub mod derive_more {
504 pub use ::derive_more::*;
509}
510
511#[cfg(feature = "env_logger")]
512pub mod env_logger {
513 pub use ::env_logger::*;
518}
519
520#[cfg(feature = "extension-trait")]
521pub mod extension_trait {
522 pub use ::extension_trait::*;
527}
528
529#[cfg(feature = "futures")]
530pub mod futures {
531 pub use ::futures::*;
536}
537
538#[cfg(feature = "hex")]
539pub mod hex {
540 pub use ::hex::*;
545}
546
547#[cfg(feature = "http")]
548pub mod http {
549 pub use ::http::*;
554}
555
556#[cfg(feature = "hyper")]
557pub mod hyper {
558 pub use ::hyper::*;
563}
564
565#[cfg(feature = "itertools")]
566pub mod itertools {
567 pub use ::itertools::*;
572}
573
574#[cfg(feature = "jiff")]
575pub mod jiff {
576 pub use ::jiff::*;
581}
582
583#[cfg(feature = "json5")]
584pub mod json5 {
585 pub use ::json5::*;
590}
591
592#[cfg(feature = "libc")]
593pub mod libc {
594 pub use ::libc::*;
599}
600
601#[cfg(feature = "log")]
602pub mod log {
603 pub use ::log::*;
608}
609
610#[cfg(feature = "mime")]
611pub mod mime {
612 pub use ::mime::*;
617}
618
619#[cfg(feature = "nom")]
620pub mod nom {
621 pub use ::nom::*;
626}
627
628#[cfg(feature = "num-bigint")]
629pub mod num_bigint {
630 pub use ::num_bigint::*;
635}
636
637#[cfg(feature = "num_cpus")]
638pub mod num_cpus {
639 pub use ::num_cpus::*;
644}
645
646#[cfg(feature = "num_enum")]
647pub mod num_enum {
648 pub use ::num_enum::*;
653}
654
655#[cfg(feature = "proc-macro2")]
656pub mod proc_macro2 {
657 pub use ::proc_macro2::*;
662}
663
664#[cfg(feature = "proptest")]
665pub mod proptest {
666 pub use ::proptest::*;
671}
672
673#[cfg(feature = "quote")]
674pub mod quote {
675 pub use ::quote::*;
680}
681
682#[cfg(feature = "rand")]
683pub mod rand {
684 pub use ::rand::*;
689}
690
691#[cfg(feature = "rand_chacha")]
692pub mod rand_chacha {
693 pub use ::rand_chacha::*;
698}
699
700#[cfg(feature = "rand_pcg")]
701pub mod rand_pcg {
702 pub use ::rand_pcg::*;
707}
708
709#[cfg(feature = "rayon")]
710pub mod rayon {
711 pub use ::rayon::*;
716}
717
718#[cfg(feature = "regex")]
719pub mod regex {
720 pub use ::regex::*;
725}
726
727#[cfg(feature = "reqwest")]
728pub mod reqwest {
729 pub use ::reqwest::*;
734}
735
736#[cfg(feature = "rustyline")]
737pub mod rustyline {
738 pub use ::rustyline::*;
743}
744
745#[cfg(feature = "semver")]
746pub mod semver {
747 pub use ::semver::*;
752}
753
754#[cfg(feature = "serde")]
755pub mod serde {
756 pub use ::serde::*;
761}
762
763#[cfg(feature = "serde_json")]
764pub mod serde_json {
765 pub use ::serde_json::*;
770}
771
772#[cfg(feature = "sha2")]
773pub mod sha2 {
774 pub use ::sha2::*;
779}
780
781#[cfg(feature = "socket2")]
782pub mod socket2 {
783 pub use ::socket2::*;
788}
789
790#[cfg(feature = "static_assertions")]
791pub mod static_assertions {
792 pub use ::static_assertions::*;
797}
798
799#[cfg(feature = "syn")]
800pub mod syn {
801 pub use ::syn::*;
806}
807
808#[cfg(feature = "tempfile")]
809pub mod tempfile {
810 pub use ::tempfile::*;
815}
816
817#[cfg(feature = "tera")]
818pub mod tera {
819 pub use ::tera::*;
824}
825
826#[cfg(feature = "termcolor")]
827pub mod termcolor {
828 pub use ::termcolor::*;
833}
834
835#[cfg(feature = "thiserror")]
836pub mod thiserror {
837 pub use ::thiserror::*;
842}
843
844#[cfg(feature = "tokio")]
845pub mod tokio {
846 pub use ::tokio::*;
851}
852
853#[cfg(feature = "tower")]
854pub mod tower {
855 pub use ::tower::*;
861}
862
863#[cfg(feature = "toml")]
864pub mod toml {
865 pub use ::toml::*;
870}
871
872#[cfg(feature = "unicode-segmentation")]
873pub mod unicode_segmentation {
874 pub use ::unicode_segmentation::*;
879}
880
881#[cfg(feature = "url")]
882pub mod url {
883 pub use ::url::*;
888}
889
890#[cfg(feature = "walkdir")]
891pub mod walkdir {
892 pub use ::walkdir::*;
897}
898
899#[cfg(feature = "xshell")]
900pub mod xshell {
901 pub use ::xshell::*;
906}