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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
#![cfg_attr(not(feature = "std"), no_std)]
//! [](https://gitlab.nebula.technology/libraries/rust/gearbox/-/commits/main)
//! [](https://gitlab.nebula.technology/libraries/rust/gearbox/-/commits/main)
//! [](https://gitlab.nebula.technology/libraries/rust/gearbox/-/releases)
//!
//! Gearbox is a versatile library that encompasses a wide array of functionalities, including networking, logging,
//! railway-oriented programming extensions, and time management. Initially designed as a collection of utilities, the
//! ultimate vision for Gearbox is to evolve into a highly optimized, standalone toolkit. The goal is to minimize external
//! dependencies progressively, leading to a library that is lightweight and efficient. By doing so, Gearbox aims to be
//! universally compatible, from embedded systems to WebAssembly (WASM) environments, all while maintaining simplicity and
//! minimizing the need for boilerplate code. This development strategy positions Gearbox as a comprehensive solution for
//! developers seeking to build efficient, scalable applications across a broad spectrum of platforms.
//!
//! # Features
//!
//! | Category | Feature | use | Description | Status |
//! |------------|-----------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
//! | Common | TryDefault | gearbox::common::TryDefault | This is a trait used internally in `Gearbox` defining a `TryDefault` trait that returns a Result<T,Self::Error>. It can also be used in other systems. | ✅ |
//! | | BoxedFuture | gearbox::common::BoxedFuture | Type alias for a pinned boxed future. Used for returning dynamically dispatched futures. | ✅ |
//! | Error | ErrorTracer | gearbox::error::tracer::* | An error structure that builds a traceable stack of errors. It allows breaking down the error into a TypeId to define the encapsulated error for further operations. Contains information about file, line, module path, and optional error_code with display and debug. This also comes with the macro `Error!()` which sets up the `ErrorTracerExtInfo` with all the needed information (file, line, module). | ⚠️ |
//! | | Rail ErrorTracer | gearbox::rails::ext::map_err_tracer | Simplification for `map_err` for operating with the ErrorTracer, allowing for passing an `Error!()` or an `ErrorTracerExtInfo` for collecting all the information. | ✅ |
//! | Logging | Tracing Log Formatter | gearbox::log::fmt::* | Custom subscriber for formatting logs when using the rust Tracing library. | ⚠️ |
//! | Networking | hostname | gearbox::net::hostname | Get the hostname of the local machine. | ✅ |
//! | | HTTP Request | gearbox::net::http::request | Send an HTTP request. This is an extension on top of `Reqwest` that simplifies the implementation of mTLS and payload signing. | ⚠️ |
//! | | HTTP Request Chaining | gearbox::net::http::request_chain | Chaining system for HTTP requests, allowing for chaining requests and responses for more advanced request/response handling. | ❌ |
//! | Paths | Common Paths | gearbox::path::* | Common paths under Windows, Linux, and more. For example, under Linux, the config path is usually `~/.config/`. | ✅ |
//! | Rails | Common Extensions | gearbox::rails::ext::* | Various extension traits for operating on `Result`, `Option`, and other standard types, providing additional methods for error handling, merging results, and tapping into values. | ⚠️ |
//! | | Future Extensions | gearbox::rails::ext::future::* | Extensions for working with `Future` types, providing methods for mapping, chaining, and merging futures. | ✅ |
//! | serde | Dynamic Serialization | gearbox::serde::dynamic::* | Dynamic serialization system that allows for encoding and decoding of multiple formats. This is a simplified version of the serde library. | ⚠️ |
//! | | Wasm Bindgen Ser/de | gearbox::serde::wasm_bindgen::* | Implementation for WASM Bind Generator that allows for serialization/deserialization of JsValue. | ✅ |
//! | Storage | Web Storage | gearbox::storage::web::local_storage::* | Interface for interacting with local storage in a web environment, including features for setting, getting, and deleting data with JSON serialization/deserialization support. | 🚧 |
//! | | File Storage | gearbox::storage::io::file::* | Interface for interacting with file storage, including features for setting, getting, and deleting data with JSON and YAML serialization/deserialization support. | 🧪 |
//! | | Selective Storage | gearbox::storage::selective_storage | Trait for selective storage operations, providing methods for creating, setting, getting, and deleting storage entries. | 🚧 |
//! | Time | Time Stamps and more | gearbox::time::* | Timestamp system similar to Chrono, handling times and time calculations. Used throughout Gearbox instead of Chrono. | ⚠️ |
//! | Template | Template Engine | gearbox::template::* | Template engine responsible for rendering templates using context data and applying pipelines for data transformations. It supports pipelines for operations like date formatting and string prefixing. | ⚠️ |
//!
//! ### Status Icons Explanation
//!
//! - ✅ Completed: The feature is fully implemented and tested.
//! - ❌ Not Completed: The feature is not implemented.
//! - ⚠️ Partially: The feature is partially implemented.
//! - 🚧 In Development: The feature is currently being developed.
//! - 🧪 Missing Testing: The feature is implemented but lacks testing.
//!
//! # Test Status
//! [See Test Status](./TEST_STATUS.md)
//!
//!
//! # Http Request (gearbox::net::http::request)
//!
//! ## Complete architectural overview:
//! ```mermaid
//! classDiagram
//! %% Package: request
//! namespace request {
//! class Client {
//! +client: reqwest::Client
//! +new()
//! +with_client(reqwest::Client)
//! +set_global_signing(Signature)
//! }
//!
//! class Error {
//! +UrlParser(ParseError)
//! +Request(reqwest::Error)
//! +NoUrl
//! +HeaderValue(reqwest::header::InvalidHeaderValue)
//! +DeserializeContentType(String)
//! +DeserializeJson(serde_json::Error)
//! +BodyError(TracerError)
//! }
//!
//! class Method {
//! <<enumeration>>
//! Get
//! Post
//! Put
//! Delete
//! Patch
//! Head
//! Options
//! Connect
//! Trace
//! None
//! }
//!
//! class RequestBuilder {
//! +client: Option<Arc<Client>>
//! +method: Method
//! +uri: Option<Url>
//! +headers: HeaderMap
//! +body: Body
//! +content_type: String
//! +signature: Option<Signature>
//! +new_with_client(client: Option<Client>, method: Method, uri: Url)
//! +method(T: Into<Method>)
//! +uri(uri: &str)
//! +header(H: Into<Header>)
//! +headers(H: Into<HeaderMap>)
//! +body(B: Into<Body>)
//! +content_type(content_type: &str)
//! +with_signing_default()
//! +with_signing(signature: Signature)
//! +send()
//! }
//!
//! class Response {
//! +status: StatusCode
//! +headers: HeaderMap
//! +content_length: Option<u64>
//! +url: Url
//! +body: BodyOwned
//! +status()
//! +to(T: DeserializeOwned)
//! }
//!
//! class StatusCode {
//! +code: u16
//! +reason: &'static str
//! +as_u16()
//! +as_str()
//! }
//!
//! class Url {
//! +Simple(url: String)
//! }
//!
//! class Body {
//! +Empty
//! }
//!
//! class BodyOwned {
//! +from(box_raw: Box<reqwest::Response>)
//! }
//! }
//!
//! %% Relationships
//! Client --> RequestBuilder
//! RequestBuilder --> Response
//! RequestBuilder --> Error
//! Response --> StatusCode
//! Response --> HeaderMap
//! Response --> Url
//! Response --> BodyOwned
//! HeaderMap --> Header
//! Header --> Name
//! Header --> Values
//! Values --> Value
//! ```
//!
//!
//! # Http Request Chaining (gearbox::net::http::request_chaining)
//!
//! ## Complete architectural overview:
//! ```mermaid
//! classDiagram
//! %% Package: request
//! namespace request {
//! class Client {
//! +client: reqwest::Client
//! +new()
//! +with_client(reqwest::Client)
//! +set_global_signing(Signature)
//! }
//!
//! class Error {
//! +UrlParser(ParseError)
//! +Request(reqwest::Error)
//! +NoUrl
//! +HeaderValue(reqwest::header::InvalidHeaderValue)
//! +DeserializeContentType(String)
//! +DeserializeJson(serde_json::Error)
//! +BodyError(TracerError)
//! }
//!
//! class Method {
//! <<enumeration>>
//! Get
//! Post
//! Put
//! Delete
//! Patch
//! Head
//! Options
//! Connect
//! Trace
//! None
//! }
//!
//! class RequestBuilder {
//! +client: Option<Arc<Client>>
//! +method: Method
//! +uri: Option<Url>
//! +headers: HeaderMap
//! +body: Body
//! +content_type: String
//! +signature: Option<Signature>
//! +new_with_client(client: Option<Client>, method: Method, uri: Url)
//! +method(T: Into<Method>)
//! +uri(uri: &str)
//! +header(H: Into<Header>)
//! +headers(H: Into<HeaderMap>)
//! +body(B: Into<Body>)
//! +content_type(content_type: &str)
//! +with_signing_default()
//! +with_signing(signature: Signature)
//! +send()
//! }
//!
//! class Response {
//! +status: StatusCode
//! +headers: HeaderMap
//! +content_length: Option<u64>
//! +url: Url
//! +body: BodyOwned
//! +status()
//! +to(T: DeserializeOwned)
//! }
//!
//! class StatusCode {
//! +code: u16
//! +reason: &'static str
//! +as_u16()
//! +as_str()
//! }
//!
//! class Url {
//! +Simple(url: String)
//! }
//!
//! class Body {
//! +Empty
//! }
//!
//! class BodyOwned {
//! +from(box_raw: Box<reqwest::Response>)
//! }
//! }
//!
//! %% Package: request_chaining
//! namespace request_chaining {
//! class Header {
//! +name: Name
//! +values: Values
//! }
//!
//! class HeaderMap {
//! +inner: HashMap<Name, Values>
//! +get(K: Into<Name>)
//! +insert(header: Header)
//! +extend(headers: HeaderMap)
//! }
//!
//! class Name {
//! +String name
//! }
//!
//! class Values {
//! +Vec<Value> values
//! +iter()
//! }
//!
//! class Value {
//! +Vec<u8> value
//! +as_bytes()
//! +to_vec()
//! }
//!
//! class TracerError
//! class Signature
//! class ParseError
//! }
//!
//! %% Relationships
//! Client --> RequestBuilder
//! RequestBuilder --> Response
//! RequestBuilder --> Error
//! Response --> StatusCode
//! Response --> HeaderMap
//! Response --> Url
//! Response --> BodyOwned
//! HeaderMap --> Header
//! Header --> Name
//! Header --> Values
//! Values --> Value
//! ```
//!
//! # Signature (gearbox::net::signature)
//! ([docs: gearbox::net::signature](./src/net/signature/mod.rs))
//!
//!
//! # Railway Future extension (gearbox::rails::ext::future)
//! ([docs: gearbox::serde::dynamic](./src/rails/ext/future/mod.rs))
//!
//! # Dynamic Serialization/Deserialization (gearbox::serde::dynamic)
//! ([docs: gearbox::serde::dynamic](./src/serde/dynamic/mod.rs))
//!
//! # RwArc (gearbox::sync::rw_arc)
//! ([docs: gearbox::sync::rw_arc](./src/sync/rw_arc/mod.rs))
//!
//! # RwArc (gearbox::template)
//! ([docs: gearbox::template](./src/template/mod.rs))
//!
//! ## TODO
//!
//! - [ ] ( gearbox::log::* ) Clean up Log fmt/syslog, some of the code can be combined and cleaned up a bit better, also the formatter supports syslog, and bunyan, this should probably be cleared up a bit more, and separated better.
//! - [ ] ( gearbox::path::* ) current this system is mainly just exposing the dirs::* library, this should be removed.
//! - [ ] ( gearbox::* ) Remove usage for Vec or move usage of std::vec::Vec to another no-std library
//!
//!
//!
//
// Core System
//
extern crate core;
//
// Standard system
//
#[cfg(feature = "std")]
extern crate std;
//
// Dependencies already in CORE
//
extern crate alloc;
//
// Optional Dependencies
//
#[cfg(feature = "axum")]
extern crate axum;
#[cfg(feature = "base64")]
extern crate base64;
#[cfg(feature = "bs58")]
extern crate bs58;
#[cfg(feature = "bson")]
extern crate bson;
#[cfg(feature = "bytes")]
extern crate bytes;
#[cfg(feature = "derive_more")]
#[macro_use]
extern crate derive_more;
#[cfg(feature = "didkit")]
extern crate didkit;
#[cfg(feature = "erased_serde")]
extern crate erased_serde;
#[cfg(feature = "flexbuffers")]
extern crate flexbuffers;
#[cfg(feature = "futures")]
extern crate futures;
#[cfg(feature = "gearbox_macros")]
#[macro_use]
extern crate gearbox_macros;
#[cfg(feature = "hashbrown")]
extern crate hashbrown;
#[cfg(feature = "hex")]
extern crate hex;
#[cfg(feature = "hmac")]
extern crate hmac; // ## For Testing!
#[cfg(feature = "hyper")]
extern crate hyper;
#[cfg(feature = "hyper_util")]
extern crate hyper_util;
#[cfg(feature = "if_addrs")]
extern crate if_addrs;
#[cfg(feature = "json5")]
extern crate json5;
#[cfg(feature = "pnet")]
extern crate pnet;
#[cfg(feature = "postcard")]
extern crate postcard;
#[cfg(feature = "reqwest")]
extern crate reqwest;
#[cfg(feature = "rmp_serde")]
extern crate rmp_serde;
#[cfg(feature = "ron")]
extern crate ron;
#[cfg(feature = "semver")]
extern crate semver;
#[cfg(feature = "dep_serde")]
extern crate serde as crate_serde;
#[cfg(feature = "serde_cbor")]
extern crate serde_cbor;
#[cfg(feature = "serde_derive")]
extern crate serde_derive;
#[cfg(feature = "serde_json")]
extern crate serde_json;
#[cfg(feature = "serde_lexpr")]
extern crate serde_lexpr;
#[cfg(feature = "serde_pickle")]
extern crate serde_pickle as pickle;
#[cfg(feature = "serde_qs")]
extern crate serde_qs;
#[cfg(feature = "serde_xml_rs")]
extern crate serde_xml_rs;
#[cfg(feature = "serde_yaml")]
extern crate serde_yaml;
#[cfg(feature = "sha2")]
extern crate sha2;
#[cfg(feature = "spin")]
extern crate spin;
#[cfg(feature = "tokio")]
extern crate tokio;
#[cfg(feature = "tracing")]
extern crate tracing;
#[cfg(feature = "tracing_subscriber")]
extern crate tracing_subscriber;
#[cfg(feature = "uniffi")]
extern crate uniffi;
#[cfg(feature = "uniffi_macros")]
extern crate uniffi_macros;
#[cfg(test)]
#[macro_use]
extern crate wasm_bindgen_test;
#[cfg(all(target_arch = "wasm32", feature = "web"))]
extern crate web_sys;
#[cfg(all(feature = "syslog-macro", feature = "log-macro"))]
compile_error!("`syslog-macro` and `log-macro` cannot be enabled at the same time.");
// uniffi::setup_scaffolding!();
#[cfg(feature = "collections")]
pub mod collections;
#[cfg(feature = "common")]
pub mod common;
#[cfg(feature = "did")]
pub mod did;
#[cfg(feature = "error")]
pub mod error;
#[cfg(feature = "log")]
pub mod log;
#[cfg(feature = "net")]
pub mod net;
#[cfg(feature = "path")]
pub mod path;
#[cfg(feature = "rails")]
pub mod rails;
#[cfg(feature = "serde")]
pub mod serde;
#[cfg(feature = "service")]
pub mod service;
#[cfg(feature = "storage")]
pub mod storage;
#[cfg(feature = "sync")]
pub mod sync;
#[cfg(feature = "task")]
pub mod task;
#[cfg(feature = "template")]
pub mod template;
#[cfg(feature = "time")]
pub mod time;
#[allow(unused_imports)]
#[cfg(all(
feature = "log-tracing-macros",
not(feature = "log-tracing-macros-syslog")
))]
pub use crate::log::tracing::macros::common::*;
#[allow(unused_imports)]
#[cfg(feature = "log-tracing-macros-syslog")]
pub use crate::log::tracing::macros::syslog::*;
#[cfg(feature = "error-tracer-macros")]
#[allow(unused_imports)]
pub use crate::error::tracer::error_macro::*;
pub mod macros {
pub mod loaders {
#[cfg(feature = "gearbox_macros")]
pub use gearbox_macros::load_consts;
}
}
pub mod externs {
pub mod collections {
#[cfg(feature = "hashbrown")]
pub use hashbrown::HashMap;
#[cfg(feature = "hashbrown")]
pub use hashbrown::HashSet;
}
#[cfg(target_arch = "wasm32")]
pub mod wasm_bindgen {
pub use wasm_bindgen::__rt;
pub use wasm_bindgen::convert;
pub use wasm_bindgen::describe;
pub use wasm_bindgen::prelude;
}
#[cfg(feature = "dep_serde")]
pub mod serde {
pub use crate_serde::*;
pub mod derive {
pub use serde_derive::*;
}
#[cfg(feature = "with_json")]
pub mod json {
pub use serde_json::*;
}
}
pub use core::{cell, fmt, marker, mem, ops, ptr};
pub mod sync {
pub use alloc::sync::Arc;
pub use core::sync::atomic;
}
pub mod rc {
pub use alloc::rc::Rc;
}
}
#[cfg(test)]
mod tests {}