unwrap_enum/
lib.rs

1// Copyright (C) 2024 John Turner
2
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16//! # unwrap-enum
17//! A crate to generate methods to unwrap enums as certain variants, like `is_some`
18//! and `is_none` on `Option`.
19//!
20//! # Example
21//! ```rust
22//! use unwrap_enum::{EnumAs, EnumIs};
23//!
24//! #[derive(Clone, Debug, EnumAs, EnumIs)]
25//! enum Value {
26//!     String(String),
27//!     Int(i64)
28//! }
29//!
30//! let value = Value::String("hello world".to_string());
31//!
32//! assert!(value.is_string());
33//! assert!(!value.is_int());
34//! assert!(matches!(value.as_string(), Some(string) if string == "hello world"));
35//! assert!(matches!(value.as_int(), None));
36//! ```
37//!
38//! # Todo
39//! Implement EnumAsMut and EnumInto derive macros.
40
41pub use unwrap_enum_proc_macro::{EnumAs, EnumIs};