mod
English| 简体中文
Introduction
mod is a Rust project that provides two simple and useful utility functions for converting between Option and Result types. The project includes two main functions:
option_to_result<T, E>: Converts anOption<T>to aResult<T, E>.result_to_option<T, E>: Converts aResult<T, E>to anOption<T>.
Installation
You can add this project to your Rust project by running the following command:
Usage
First, ensure that you include the mod crate in your project:
extern crate mod;
use mod::;
Function Descriptions
option_to_result
Converts an Option<T> to a Result<T, E>. If the Option is Some, it returns the value wrapped in Ok; if it is None, it returns the specified error.
Example:
let some_value = Some;
let none_value: = None;
let error = "Error";
assert_eq!;
assert_eq!;
result_to_option
Converts a Result<T, E> to an Option<T>. If the Result is Ok, it returns the value wrapped in Some; if it is Err, it returns None.
Example:
let ok_result = Ok::;
let err_result = Err::;
assert_eq!;
assert_eq!;
Testing
This project includes some unit tests to verify the correctness of the functionality. You can run the tests by executing the following command:
The test cases are located in the tests module and cover the option_to_result and result_to_option functions:
License
This project is licensed under the GPL license. See the LICENSE file for details.
Contribution
Contributions are welcome! Please submit issues or pull requests.
Thank you for using mod! If you have any questions or suggestions, feel free to contact us.