Skip to main content

rust_zero_core/
lib.rs

1//! Framework-neutral runtime primitives shared by rust-zero services.
2//!
3//! The crate provides configuration loading, circuit breaking, adaptive load shedding,
4//! consistent hashing, and async retry helpers.  They intentionally do not depend on a
5//! particular HTTP or gRPC framework so REST, RPC, and background services can share them.
6
7pub mod auth;
8pub mod balancer;
9pub mod bloom;
10pub mod breaker;
11pub mod cache;
12pub mod config;
13pub mod config_center;
14pub mod discov;
15#[cfg(feature = "etcd")]
16pub mod etcd;
17pub mod executor;
18pub mod fx;
19pub mod hash;
20pub mod health;
21#[cfg(feature = "kubernetes")]
22pub mod kubernetes;
23pub mod limit;
24pub mod load;
25pub mod log;
26pub mod metric;
27pub mod profile;
28pub mod pubsub;
29pub mod queue;
30pub mod rolling;
31pub mod service;
32pub mod singleflight;
33#[cfg(feature = "stores-mongo")]
34pub mod stores_mongo;
35#[cfg(feature = "stores-redis")]
36pub mod stores_redis;
37#[cfg(feature = "stores-sql")]
38pub mod stores_sql;
39#[cfg(feature = "telemetry")]
40pub mod telemetry;
41pub mod trace;
42pub mod validation;
43
44pub use auth::{
45    decode_jwt_hs256, encode_jwt_hs256, sign_request, AuthFailure, JwtClaimProjection,
46    JwtValidationError, RequestSignature, RequestSignatureVerifier, AUTH_KEY_ID_HEADER,
47    AUTH_SIGNATURE_HEADER, AUTH_TIMESTAMP_HEADER,
48};
49pub use balancer::{BalancerError, NodeSnapshot, P2cBalancer, P2cRequest};
50pub use bloom::{BloomError, BloomFilter};
51pub use breaker::{
52    BreakerState, CircuitBreaker, CircuitBreakerConfig, CircuitBreakerError, CircuitBreakerPermit,
53    CircuitBreakerPolicy, CircuitBreakerSnapshot, CircuitOutcome, RollingCircuitBreakerConfig,
54};
55pub use cache::{CacheStats, MemoryCache, ReadThroughCache, TtlCache};
56pub use config::{load_config, parse_config, ConfigError, ConfigFormat, ServiceConfig};
57pub use config_center::{ConfigCenterError, ConfigSnapshot, DynamicConfig};
58pub use discov::{
59    DiscoveredEndpoint, DiscoveryError, DiscoveryReconnectBackoff, EndpointChangeFuture,
60    EndpointSubscription, ServiceEvent, ServiceLease, ServiceRegistry, ServiceSubscription,
61};
62#[cfg(feature = "etcd")]
63pub use etcd::{
64    EtcdClient, EtcdConfig, EtcdConfigWatcher, EtcdError, EtcdServiceLease, EtcdServiceSubscription,
65};
66pub use executor::{
67    BatchExecutor, BatchExecutorError, ChunkExecutor, DelayExecutor, DelayExecutorError,
68    LessExecutor, PeriodicExecutor, PeriodicExecutorError,
69};
70pub use fx::{retry, timeout, RetryPolicy};
71pub use hash::ConsistentHash;
72pub use health::{HealthRegistry, HealthSnapshot};
73#[cfg(feature = "kubernetes")]
74pub use kubernetes::{
75    KubernetesDiscovery, KubernetesDiscoveryConfig, KubernetesDiscoveryError,
76    KubernetesServiceSubscription,
77};
78pub use limit::{LimitDecision, PeriodLimiter, TokenLimiter};
79#[cfg(feature = "stores-redis")]
80pub use limit::{RedisLimiterSnapshot, RedisPeriodLimiter, RedisTokenLimiter};
81pub use load::{
82    AdaptiveShedder, LoadShedderConfig, LoadShedderMode, LoadShedderSnapshot, ShedPermit,
83};
84pub use log::{
85    LogConfig, LogContext, LogEncoding, LogError, LogField, LogLevel, LogSampler, LogTarget,
86    Logger, RotationPolicy, Sensitive,
87};
88pub use metric::{
89    CounterVec, GaugeVec, HistogramOptions, HistogramVec, Metrics, MetricsError, VectorOptions,
90};
91pub use profile::{ProfilePoint, ProfileSnapshot, Profiler};
92pub use pubsub::{Broker, Subscription};
93pub use queue::{
94    BalancedPusher, FanoutPusher, PushError, PusherConfigError, QueueConfigError, QueueEvent,
95    QueueMetrics, QueueProducer, QueueReceiver, QueueRuntime, QueueRuntimeConfig,
96    QueueRuntimeError, QueueSender, RunningQueue,
97};
98pub use rolling::{RollingSnapshot, RollingWindow};
99pub use service::{
100    wait_for_shutdown_signal, RunningServices, ServiceGroup, ServiceGroupError, Shutdown,
101    ShutdownHandle, ShutdownSignal,
102};
103pub use singleflight::{SingleFlight, SingleFlightError};
104#[cfg(feature = "stores-mongo")]
105pub use stores_mongo::{
106    CachedMongoCollection, MongoCacheConfig, MongoStore, MongoStoreConfig, MongoStoreError,
107    MongoStoreMetrics,
108};
109#[cfg(feature = "stores-redis")]
110pub use stores_redis::{
111    RedisCacheError, RedisJsonCache, RedisLock, RedisModelCache, RedisModelCacheConfig,
112    RedisModelCacheError, RedisStore, RedisStoreConfig, RedisStoreError, RedisStoreMetrics,
113    RedisSubscription, RedisSubscriptionConfig, RedisSubscriptionEvent, RedisSubscriptionMessage,
114    RedisTtl,
115};
116#[cfg(feature = "stores-sql")]
117pub use stores_sql::{
118    CachedSqlStore, MySqlStore, PostgresStore, SqlCacheConfig, SqlStore, SqlStoreConfig,
119    SqlStoreError, SqlStoreMetrics, SqliteStore,
120};
121#[cfg(feature = "telemetry")]
122pub use telemetry::{
123    OtlpTransport, Telemetry, TelemetryConfig, TelemetryError, TelemetrySpan, TelemetrySpanKind,
124};
125pub use trace::{TraceContext, TraceContextError, TraceFlags};
126pub use validation::{Validate, Validation, ValidationErrors, Violation};