ri/core/mod.rs
1//! Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
2//!
3//! This file is part of Ri.
4//! The Ri project belongs to the Dunimd Team.
5//!
6//! Licensed under the Apache License, Version 2.0 (the "License");
7//! You may not use this file except in compliance with the License.
8//! You may obtain a copy of the License at
9//!
10//! http://www.apache.org/licenses/LICENSE-2.0
11//!
12//! Unless required by applicable law or agreed to in writing, software
13//! distributed under the License is distributed on an "AS IS" BASIS,
14//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//! See the License for the specific language governing permissions and
16//! limitations under the License.
17
18//! # Core Runtime Module
19//!
20//! The core module provides the fundamental building blocks for Ri applications,
21//! including the application builder, service context, error handling, and module lifecycle management.
22//!
23//! ## Key Components
24//!
25//! - **error**: Error handling with custom error types and result aliases
26//! - **context**: Service context for accessing core functionalities
27//! - **module**: Module system for extending Ri with custom functionality
28//! - **runtime**: Application runtime and builder for constructing Ri applications
29//! - **lifecycle**: Lifecycle management for modules
30//! - **analytics**: Basic analytics and telemetry support
31//!
32//! ## Design Principles
33//!
34//! The core module follows the following design principles:
35//!
36//! 1. **Dependency Injection**: Components are accessed through the service context,
37//! allowing for easy mocking and testing
38//! 2. **Builder Pattern**: The `RiAppBuilder` provides a fluent API for configuring applications
39//! 3. **Module System**: A flexible module system allows for easy extension
40//! 4. **Error Handling**: A unified error type simplifies error management across modules
41//! 5. **Async First**: Full support for asynchronous operations
42//!
43//! ## Usage Example
44//!
45//! ```rust
46//! use ri::prelude::*;
47//!
48//! #[tokio::main]
49//! async fn main() -> RiResult<()> {
50//! let app = RiAppBuilder::new()
51//! .with_config("config.yaml")?
52//! .with_module(Box::new(MyModule::new()))
53//! .build()?;
54//!
55//! app.run(|ctx| async move {
56//! ctx.logger().info("service", "Ri service started")?;
57//! Ok(())
58//! }).await
59//! }
60//! ```
61
62/// Error handling with custom error types and result aliases
63pub mod error;
64/// Safe lock utilities for concurrent programming
65pub mod lock;
66/// Service context for accessing core functionalities
67pub mod context;
68/// Module system for extending Ri with custom functionality
69pub mod module;
70/// Application runtime and builder for constructing Ri applications
71pub mod runtime;
72/// Application builder for constructing Ri applications
73pub mod app_builder;
74/// Application runtime for managing Ri application lifecycle
75pub mod app_runtime;
76/// Module types for distinguishing between sync and async modules
77pub mod module_types;
78/// Module sorter for sorting modules based on dependencies and priority
79pub mod module_sorter;
80/// Lifecycle management for modules
81pub mod lifecycle;
82/// Basic analytics and telemetry support
83pub mod analytics;
84/// Health checks for modules and services
85pub mod health;
86/// Error chain utilities
87pub mod error_chain;
88/// Sharded lock implementation for improved concurrent performance
89pub mod concurrent;
90
91/// Main error type for Ri operations
92pub use error::{RiError, RiResult};
93/// Service context providing access to core functionalities
94pub use context::RiServiceContext;
95/// Module traits for extending Ri functionality
96pub use module::RiModule;
97/// Application builder and runtime for constructing Ri applications
98pub use runtime::{RiAppBuilder, RiAppRuntime};
99/// Internal module traits
100pub use module::{ServiceModule, AsyncServiceModule};
101
102/// Lock utilities
103#[cfg(feature = "pyo3")]
104pub use lock::{RiLockError, RiLockResult, RwLockExtensions, MutexExtensions, from_poison_error};
105
106/// Python module bindings
107#[cfg(feature = "pyo3")]
108pub use module::{RiPythonModule, RiPythonModuleAdapter, RiPythonServiceModule, RiPythonAsyncServiceModule};
109
110/// Error chain utilities
111#[cfg(feature = "pyo3")]
112pub use error_chain::{RiErrorChain, RiErrorChainIter, RiErrorContext, RiOptionErrorContext};
113
114/// Health check types
115#[cfg(feature = "pyo3")]
116pub use health::{RiHealthStatus, RiHealthCheckResult, RiHealthCheckConfig, RiHealthReport, RiHealthChecker};
117
118/// Lifecycle management
119#[cfg(feature = "pyo3")]
120pub use lifecycle::RiLifecycleObserver;
121
122/// Analytics module
123#[cfg(feature = "pyo3")]
124pub use analytics::RiLogAnalyticsModule;
125
126/// Sharded lock types
127#[cfg(feature = "pyo3")]
128pub use concurrent::RiShardedLockStats;