use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
pub enum Variant {
#[default]
Fn,
FinalFn,
EntryPoint,
Finalize,
View,
}
impl Variant {
pub fn is_entry(self) -> bool {
matches!(self, Variant::EntryPoint)
}
pub fn is_finalize(self) -> bool {
matches!(self, Variant::Finalize)
}
pub fn is_onchain(self) -> bool {
matches!(self, Variant::Finalize | Variant::FinalFn | Variant::View)
}
pub fn is_finalize_context(self) -> bool {
matches!(self, Variant::Finalize | Variant::FinalFn)
}
pub fn is_view(self) -> bool {
matches!(self, Variant::View)
}
pub fn is_externally_callable(self) -> bool {
matches!(self, Variant::EntryPoint | Variant::View)
}
}
impl fmt::Display for Variant {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::FinalFn => write!(f, "final fn"),
Self::Fn => write!(f, "fn"),
Self::EntryPoint => write!(f, "entry"),
Self::Finalize => write!(f, "finalize"),
Self::View => write!(f, "view fn"),
}
}
}