option-like

Crates.iooption-like
lib.rsoption-like
version0.1.4
created_at2025-03-19 06:59:39.693787+00
updated_at2025-03-24 05:26:46.149883+00
descriptionCreate your own Option-like enum
homepagehttps://github.com/DenisGorbachev/option-like
repositoryhttps://github.com/DenisGorbachev/option-like
max_upload_size
id1597763
size37,360
Denis Gorbachev (DenisGorbachev)

documentation

README

Create your own Option-like enum

Build Documentation

Create your own enum type that behaves like Rust’s Option but with custom names.

Example

use option_like::option_like;

option_like!(
    #[derive(Debug, PartialEq)]
    pub enum Cached<T> {
        Hit(T),
        Miss,
    }

    is_some => is_hit
    is_none => is_miss
);

// Create instances
let c1 = Cached::<u32>::Hit(42);
let c2 = Cached::<u32>::Miss;

// Boolean tests
assert!(c1.is_hit());
assert!(c2.is_miss());

// Convert to Option
assert_eq!(Option::<u32>::from(c1), Some(42));
assert_eq!(Option::<u32>::from(c2), None);

// Convert from Option
assert_eq!(Cached::<u32>::from(Some(42)), Cached::Hit(42));
assert_eq!(Cached::<u32>::from(None), Cached::Miss);

Installation

cargo add option-like

Gratitude

Like the project? ⭐ Star this repo on GitHub!

License

Apache-2.0 or MIT.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as above, without any additional terms or conditions.

Commit count: 77

cargo fmt