#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Docstring {
pub summary: Option<String>,
pub extended_summary: Option<String>,
pub deprecation: Option<Deprecation>,
pub sections: Vec<Section>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Section {
Parameters(Vec<Parameter>),
KeywordParameters(Vec<Parameter>),
OtherParameters(Vec<Parameter>),
Receives(Vec<Parameter>),
Returns(Vec<Return>),
Yields(Vec<Return>),
Raises(Vec<ExceptionEntry>),
Warns(Vec<ExceptionEntry>),
Attributes(Vec<Attribute>),
Methods(Vec<Method>),
SeeAlso(Vec<SeeAlsoEntry>),
References(Vec<Reference>),
FreeText {
kind: FreeSectionKind,
body: String,
},
}
impl Section {
pub fn kind(&self) -> SectionKind {
match self {
Section::Parameters(_) => SectionKind::Parameters,
Section::KeywordParameters(_) => SectionKind::KeywordParameters,
Section::OtherParameters(_) => SectionKind::OtherParameters,
Section::Receives(_) => SectionKind::Receives,
Section::Returns(_) => SectionKind::Returns,
Section::Yields(_) => SectionKind::Yields,
Section::Raises(_) => SectionKind::Raises,
Section::Warns(_) => SectionKind::Warns,
Section::Attributes(_) => SectionKind::Attributes,
Section::Methods(_) => SectionKind::Methods,
Section::SeeAlso(_) => SectionKind::SeeAlso,
Section::References(_) => SectionKind::References,
Section::FreeText { kind, .. } => SectionKind::FreeText(kind.clone()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SectionKind {
Parameters,
KeywordParameters,
OtherParameters,
Receives,
Returns,
Yields,
Raises,
Warns,
Attributes,
Methods,
SeeAlso,
References,
FreeText(FreeSectionKind),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FreeSectionKind {
Notes,
Examples,
Warnings,
Todo,
Attention,
Caution,
Danger,
Error,
Hint,
Important,
Tip,
Unknown(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Parameter {
pub names: Vec<String>,
pub type_annotation: Option<String>,
pub description: Option<String>,
pub is_optional: bool,
pub default_value: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Return {
pub name: Option<String>,
pub type_annotation: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExceptionEntry {
pub type_name: String,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SeeAlsoEntry {
pub names: Vec<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Reference {
pub number: Option<String>,
pub content: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Attribute {
pub name: String,
pub type_annotation: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Method {
pub name: String,
pub type_annotation: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Deprecation {
pub version: String,
pub description: Option<String>,
}