use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NumPySectionKind {
Parameters,
Returns,
Yields,
Receives,
OtherParameters,
Raises,
Warns,
Warnings,
SeeAlso,
Notes,
References,
Examples,
Attributes,
Methods,
Unknown,
}
impl NumPySectionKind {
pub const ALL: &[NumPySectionKind] = &[
Self::Parameters,
Self::Returns,
Self::Yields,
Self::Receives,
Self::OtherParameters,
Self::Raises,
Self::Warns,
Self::Warnings,
Self::SeeAlso,
Self::Notes,
Self::References,
Self::Examples,
Self::Attributes,
Self::Methods,
];
#[rustfmt::skip]
pub fn from_name(name: &str) -> Self {
match name {
"parameters" | "parameter" | "params" | "param" => Self::Parameters,
"arguments" | "argument" | "args" | "arg" => Self::Parameters,
"returns" | "return" => Self::Returns,
"yields" | "yield" => Self::Yields,
"receives" | "receive" => Self::Receives,
"other parameters" | "other parameter" | "other params" | "other param" => Self::OtherParameters,
"other arguments" | "other argument" | "other args" | "other arg" => Self::OtherParameters,
"raises" | "raise" => Self::Raises,
"warns" | "warn" => Self::Warns,
"warnings" | "warning" => Self::Warnings,
"see also" => Self::SeeAlso,
"notes" | "note" => Self::Notes,
"references" | "reference" => Self::References,
"examples" | "example" => Self::Examples,
"attributes" | "attribute" => Self::Attributes,
"methods" | "method" => Self::Methods,
_ => Self::Unknown,
}
}
pub fn is_known(name: &str) -> bool {
!matches!(Self::from_name(name), Self::Unknown)
}
pub fn is_structured(&self) -> bool {
matches!(
self,
Self::Parameters
| Self::Returns
| Self::Yields
| Self::Receives
| Self::OtherParameters
| Self::Raises
| Self::Warns
| Self::SeeAlso
| Self::References
| Self::Attributes
| Self::Methods
)
}
pub fn is_freetext(&self) -> bool {
matches!(self, Self::Notes | Self::Examples | Self::Warnings | Self::Unknown)
}
}
impl fmt::Display for NumPySectionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Self::Parameters => "Parameters",
Self::Returns => "Returns",
Self::Yields => "Yields",
Self::Receives => "Receives",
Self::OtherParameters => "Other Parameters",
Self::Raises => "Raises",
Self::Warns => "Warns",
Self::Warnings => "Warnings",
Self::SeeAlso => "See Also",
Self::Notes => "Notes",
Self::References => "References",
Self::Examples => "Examples",
Self::Attributes => "Attributes",
Self::Methods => "Methods",
Self::Unknown => "Unknown",
};
write!(f, "{}", s)
}
}