use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GoogleSectionKind {
Args,
KeywordArgs,
OtherParameters,
Receives,
Returns,
Yields,
Raises,
Warns,
Attributes,
Methods,
SeeAlso,
Notes,
Examples,
Todo,
References,
Warnings,
Attention,
Caution,
Danger,
Error,
Hint,
Important,
Tip,
Unknown,
}
impl GoogleSectionKind {
pub const ALL: &[GoogleSectionKind] = &[
Self::Args,
Self::KeywordArgs,
Self::OtherParameters,
Self::Receives,
Self::Returns,
Self::Yields,
Self::Raises,
Self::Warns,
Self::Attributes,
Self::Methods,
Self::SeeAlso,
Self::Notes,
Self::Examples,
Self::Todo,
Self::References,
Self::Warnings,
Self::Attention,
Self::Caution,
Self::Danger,
Self::Error,
Self::Hint,
Self::Important,
Self::Tip,
];
#[rustfmt::skip]
pub fn from_name(name: &str) -> Self {
match name {
"args" | "arg" | "arguments" | "argment" => Self::Args,
"params" | "param" | "parameters" | "paramter" => Self::Args,
"keyword args" | "keyword arg" | "keyword arguments" | "keyword argument" => Self::KeywordArgs,
"keyword params" | "keyword param" | "keyword parameters" | "keyword paramter" => Self::KeywordArgs,
"other args" | "other arg" | "other arguments" | "other argment" => Self::OtherParameters,
"other params" | "other param" | "other parameters" | "other paramter" => Self::OtherParameters,
"receives" | "receive" => Self::Receives,
"returns" | "return" => Self::Returns,
"yields" | "yield" => Self::Yields,
"raises" | "raise" => Self::Raises,
"warns" | "warn" => Self::Warns,
"see also" => Self::SeeAlso,
"attributes" | "attribute" => Self::Attributes,
"methods" | "method" => Self::Methods,
"notes" | "note" => Self::Notes,
"examples" | "example" => Self::Examples,
"todo" => Self::Todo,
"references" | "reference" => Self::References,
"warnings" | "warning" => Self::Warnings,
"attention" => Self::Attention,
"caution" => Self::Caution,
"danger" => Self::Danger,
"error" => Self::Error,
"hint" => Self::Hint,
"important" => Self::Important,
"tip" => Self::Tip,
_ => 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::Args
| Self::KeywordArgs
| Self::OtherParameters
| Self::Receives
| Self::Returns
| Self::Yields
| Self::Raises
| Self::Warns
| Self::Attributes
| Self::Methods
| Self::SeeAlso
)
}
pub fn is_freetext(self) -> bool {
!self.is_structured()
}
}
impl fmt::Display for GoogleSectionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Self::Args => "Args",
Self::KeywordArgs => "Keyword Args",
Self::OtherParameters => "Other Parameters",
Self::Receives => "Receives",
Self::Returns => "Returns",
Self::Yields => "Yields",
Self::Raises => "Raises",
Self::Warns => "Warns",
Self::SeeAlso => "See Also",
Self::Attributes => "Attributes",
Self::Methods => "Methods",
Self::Notes => "Notes",
Self::Examples => "Examples",
Self::Todo => "Todo",
Self::References => "References",
Self::Warnings => "Warnings",
Self::Attention => "Attention",
Self::Caution => "Caution",
Self::Danger => "Danger",
Self::Error => "Error",
Self::Hint => "Hint",
Self::Important => "Important",
Self::Tip => "Tip",
Self::Unknown => "Unknown",
};
write!(f, "{}", s)
}
}