Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imkairat/rs_enums
rs_enums is a Python module inspired by Rust's powerful Option and Result enums.
https://github.com/imkairat/rs_enums
enum python3
Last synced: 28 days ago
JSON representation
rs_enums is a Python module inspired by Rust's powerful Option and Result enums.
- Host: GitHub
- URL: https://github.com/imkairat/rs_enums
- Owner: ImKairat
- License: mit
- Created: 2024-12-02T06:42:03.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-02T06:47:33.000Z (about 1 month ago)
- Last Synced: 2024-12-02T07:32:38.958Z (about 1 month ago)
- Topics: enum, python3
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rs_enums
![Version](https://img.shields.io/github/v/release/ImKairat/rs_enums)
[![Pylint Status](https://github.com/ImKairat/rs_enums/actions/workflows/pylint.yml/badge.svg)](https://github.com/ImKairat/rs_enums/actions/workflows/pylint.yml)
[![Pytest Status](https://github.com/ImKairat/rs_enums/actions/workflows/pytest.yml/badge.svg)](https://github.com/ImKairat/rs_enums/actions/workflows/pytest.yml)
[![Contributing Guidelines](https://img.shields.io/badge/Contributing-Guidelines-blue)](CONTRIBUTING.md)`rs_enums` is a Python module inspired by Rust’s `Option` and `Result` enums. It provides functional programming constructs for handling optional values (`Option`) and results (`Result`) with success or error outcomes. This module enables safer and more expressive code by allowing you to work with values that may or may not exist, or operations that may succeed or fail.
### Features include:
- **`Option`**: Represents a value that may or may not be present (`Some` or `None`).
- **`Result`**: Represents an operation that can either succeed (`Ok`) or fail (`Err`).
- Common methods like `is_some()`, `is_none()`, `is_ok()`, and `is_err()` are included for easy handling of these types.## Installation
Install via `pip`:
```bash
pip install rs_enums
```## Usage Example
```python
from rs_enums import Optional, Result# Example of Optional
opt = Optional(42)
if opt.is_some():
print(opt.unwrap()) # Output: 42# Example of Result
result = Result(value="Success")
if result.is_ok():
print(result.unwrap()) # Output: Success
```## License
This project is licensed under the [Apache-2.0 license](LICENSE).
## Contributing
We welcome contributions! Please see our [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on how to contribute to this project.