#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
pub use documented_macros::{
docs_const, Documented, DocumentedFields, DocumentedFieldsOpt, DocumentedOpt,
DocumentedVariants, DocumentedVariantsOpt,
};
#[doc(hidden)]
pub use phf as _private_phf_reexport_for_macro;
pub trait Documented {
const DOCS: &'static str;
}
pub trait DocumentedOpt {
const DOCS: Option<&'static str>;
}
pub trait DocumentedFields {
const FIELD_DOCS: &'static [&'static str];
const FIELD_NAMES: &'static [&'static str];
#[doc(hidden)]
fn __documented_get_index<T: AsRef<str>>(field_name: T) -> Option<usize>;
fn get_field_docs<T: AsRef<str>>(field_name: T) -> Result<&'static str, Error> {
let field_name = field_name.as_ref();
let index = Self::__documented_get_index(field_name)
.ok_or_else(|| Error::NoSuchField(field_name.into()))?;
Ok(Self::FIELD_DOCS[index])
}
}
pub trait DocumentedFieldsOpt {
const FIELD_DOCS: &'static [Option<&'static str>];
const FIELD_NAMES: &'static [&'static str];
#[doc(hidden)]
fn __documented_get_index<T: AsRef<str>>(field_name: T) -> Option<usize>;
fn get_field_docs<T: AsRef<str>>(field_name: T) -> Result<&'static str, Error> {
let field_name = field_name.as_ref();
let index = Self::__documented_get_index(field_name)
.ok_or_else(|| Error::NoSuchField(field_name.into()))?;
Self::FIELD_DOCS[index].ok_or_else(|| Error::NoDocComments(field_name.into()))
}
}
pub trait DocumentedVariants {
fn get_variant_docs(&self) -> &'static str;
}
pub trait DocumentedVariantsOpt {
fn get_variant_docs(&self) -> Option<&'static str>;
}
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
#[error(r#"The field "{0}" has no doc comments"#)]
NoDocComments(String),
#[error(r#"No field named "{0}" exists"#)]
NoSuchField(String),
}