cdumay_result
A Rust library for standardizing operation results and their serialization using serde. This crate provides a flexible and consistent way to handle operation results, including success and error cases, with support for structured data, stdout/stderr outputs, and serialization.
Features
- Structured result type with support for return values and output streams
- UUID generation for result tracking
- Integration with error handling systems
- Builder pattern for easy result construction
Installation
Add this to your Cargo.toml:
[]
= "1.0"
= "1.0" # For JSON serialization
= "1.0" # For error handling
= "1.0" # For error example
= "2.0" # For context use
Basic Usage
Here's a simple example of creating and using a successful result:
use ;
use BTreeMap;
use Value;
// Creating a successful result with data
let result = default
.stdout
.retval
.build;
// Serialize to JSON
println!;
Context Usage
Here's a simple example of creating and using a successful result using cdumay_context:
use ;
use ;
use BTreeMap;
use Serialize;
use Value;
// Creating a context
let mut context = new;
context.insert;
context.insert;
// Creating a successful result with data
let result = default
.stdout
.retval
.build;
// Serialize to JSON
println!;
Error Handling
Example using error handling with cdumay_error_standard:
use Result;
use Unexpected;
use ;
use Value;
Custom Result Builder
Example of using the builder pattern with custom data:
use ResultBuilder;
use BTreeMap;
use format;
use Value;
use Uuid;
// Create a custom result with specific UUID
let result = default
.uuid
.stdout
.retval
.build;
assert_eq!;
JSON Output Format
The JSON output format for successful results looks like this:
For error results:
License: BSD-3-Clause