oxedyne/fe2o3/fe2o3_core/src/lib.rs
3.1 KiB, 11 runs
created by r1870400018:84, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! Core functionality for the Hematite ecosystem. |
| 2 | //! |
| 3 | //! This crate provides foundational types, traits and macros used throughout Hematite. |
| 4 | //! Key features include: |
| 5 | //! |
| 6 | //! - Error handling via [`Outcome<T>`] and [`Error<T>`] with support for tagging errors |
| 7 | //! and chaining them together to preserve context during propagation |
| 8 | //! |
| 9 | //! - A flexible logging system via [`Logger`] supporting multiple output targets and |
| 10 | //! log levels with console and file support |
| 11 | //! |
| 12 | //! - Thread and bot management through [`ThreadController`] and message passing primitives |
| 13 | //! for reliable concurrent operations |
| 14 | //! |
| 15 | //! - Generic data structures and traits like [`Counter`], [`Map`], and [`Alt`] for |
| 16 | //! common programming patterns |
| 17 | //! |
| 18 | //! - Numeric type utilities via traits like [`Bound`], [`One`], and [`Zero`] with |
| 19 | //! checked arithmetic operations |
| 20 | //! |
| 21 | //! - String, path, and byte manipulation helpers with consistent error handling |
| 22 | //! |
| 23 | //! - Testing utilities with filtering and assertion support via [`test_it!`] |
| 24 | //! |
| 25 | //! - A procedural macro [`New`] for automatically implementing constructors |
| 26 | //! |
| 27 | //! # Error Handling Example |
| 28 | //! |
| 29 | //! ``` |
| 30 | //! use fe2o3_core::prelude::*; |
| 31 | //! |
| 32 | //! fn validate_age(age: i32) -> Outcome<i32> { |
| 33 | //! if age < 0 { |
| 34 | //! return Err(err!( |
| 35 | //! "Age cannot be negative, got {}", age |
| 36 | //! ), Invalid, Input)); |
| 37 | //! } |
| 38 | //! if age > 150 { |
| 39 | //! return Err(err!( |
| 40 | //! "Age seems unrealistic: {}", age |
| 41 | //! ), Invalid, Range)); |
| 42 | //! } |
| 43 | //! Ok(age) |
| 44 | //! } |
| 45 | //! ``` |
| 46 | //! |
| 47 | //! The [`New`] derive macro provides automatic constructor generation: |
| 48 | //! |
| 49 | //! ``` |
| 50 | //! use fe2o3_core::New; |
| 51 | //! |
| 52 | //! #[derive(New)] |
| 53 | //! struct Person { |
| 54 | //! name: String, |
| 55 | //! age: u32, |
| 56 | //! } |
| 57 | //! ``` |
| 58 | //! |
| 59 | #![forbid(unsafe_code)] |
| 60 | #![allow(dead_code)] |
| 61 | #![allow(unused_assignments)] |
| 62 | |
| 63 | #[macro_use] |
| 64 | pub mod macros { |
| 65 | #[macro_use] |
| 66 | pub mod error; |
| 67 | #[macro_use] |
| 68 | pub mod fallible; |
| 69 | #[macro_use] |
| 70 | pub mod meta; |
| 71 | #[macro_use] |
| 72 | pub mod string; |
| 73 | #[macro_use] |
| 74 | pub mod sync; |
| 75 | #[macro_use] |
| 76 | pub mod test; |
| 77 | } |
| 78 | |
| 79 | //pub mod alias; |
| 80 | pub mod alt; |
| 81 | pub mod bool; |
| 82 | pub mod bot; |
| 83 | pub mod byte; |
| 84 | pub mod channels; |
| 85 | pub mod conv; |
| 86 | pub mod count; |
| 87 | pub mod error; |
| 88 | pub mod file; |
| 89 | pub mod id; |
| 90 | pub mod int; |
| 91 | pub mod log; |
| 92 | pub mod map; |
| 93 | pub mod mem; |
| 94 | pub mod ord; |
| 95 | pub mod path; |
| 96 | pub mod prelude; |
| 97 | pub mod rand; |
| 98 | /// Hearing the operating system ask this process to stop. There are no signals |
| 99 | /// on `wasm32`, and the tokio feature that carries them must not reach that |
| 100 | /// build. |
| 101 | #[cfg(not(target_arch = "wasm32"))] |
| 102 | pub mod stop; |
| 103 | pub mod string; |
| 104 | pub mod term; |
| 105 | pub mod test; |
| 106 | pub mod time; |
| 107 | pub mod thread; |
| 108 | /// Runtime shims for the `wasm32` target (clock and console). |
| 109 | #[cfg(target_arch = "wasm32")] |
| 110 | pub mod wasm; |
| 111 | |
| 112 | use error::Error; |
| 113 | pub use string::contains_str; |
| 114 | |
| 115 | pub type Outcome<V> = std::result::Result<V, Error<error::ErrTag>>; |
| 116 | |
| 117 | pub trait GenTag: |
| 118 | Clone |
| 119 | + std::fmt::Debug |
| 120 | + Default |
| 121 | + std::fmt::Display |
| 122 | + Send |
| 123 | + Sync |
| 124 | + 'static |
| 125 | {} |
| 126 | |
| 127 | pub fn format_type<T>(_: T) -> String { |
| 128 | fmt!("{}", std::any::type_name::<T>()) |
| 129 | } |
| 130 | |
| 131 | pub use new::New; // The #[derive(New)] procedural macro for deriving a new function on a struct. |