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
//! anycms-core
//!
//! A unified API response library supporting multiple Rust web frameworks.
//!
//! ## Features
//! - `actix` (default): Support for actix-web framework
//! - `axum`: Support for axum framework
//! - `validator`: Integration with the `validator` crate for derive-based validation
//! - `tracing`: Automatic error logging via the `tracing` crate
//! - `full`: Enable all framework integrations
//! - `camel-case` (default): Use camelCase for JSON field names
//! - `snake-case`: Use snake_case for JSON field names
//!
//! ## Basic Usage
//! ```rust
//! use anycms_core::ApiResult;
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct User {
//! id: u32,
//! name: String,
//! }
//!
//! fn handle_request() -> ApiResult<User> {
//! let user = User { id: 1, name: "Alice".to_string() };
//! ApiResult::value(user)
//! }
//! ```
//!
//! ## Business Error Code & Timestamp
//! ```rust
//! use anycms_core::ApiResult;
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct User {
//! id: u32,
//! name: String,
//! }
//!
//! fn handle_error() -> ApiResult<User> {
//! ApiResult::fail("User not found")
//! .with_code(404)
//! .with_biz_code(10001)
//! .with_current_timestamp()
//! }
//!
//! fn handle_success() -> ApiResult<()> {
//! ApiResult::ok()
//! .with_message("Done")
//! .with_biz_code(0)
//! .with_timestamp(1700000000000)
//! }
//! ```
//!
//! ## Error Handling
//! ```rust
//! use anycms_core::ApiResult;
//!
//! fn handle_error() -> ApiResult<String> {
//! ApiResult::fail("Resource not found").with_code(404)
//! }
//! ```
//!
//! ## Validation Errors
//! ```rust
//! use anycms_core::{ApiResult, FieldError};
//!
//! fn validate() -> ApiResult<String> {
//! ApiResult::validation_errors(vec![
//! FieldError::new("email", "invalid format"),
//! ])
//! }
//! ```
//!
//! ## Request Tracing
//! ```rust
//! use anycms_core::ApiResult;
//!
//! fn handler() -> ApiResult<String> {
//! ApiResult::ok().with_trace_id("req-abc123")
//! }
//! ```
// Framework-specific implementations
// Optional integrations
// Core exports (always available)
pub use ResultPagination;
pub use ;
// Framework-specific exports (available only when corresponding feature is enabled)
pub use actix;
pub use axum;
// Optional integration exports
pub use validation_errors_to_field_errors;
pub use ApiResultTracing;