[][src]Trait structdoc::StructDoc

pub trait StructDoc {
    fn document() -> Documentation;
}

Types that can provide their own documentation at runtime.

It is provided for basic types and containers in the standard library. It should be possible to derive for most of the rest.

Examples

use structdoc::StructDoc;

#[derive(StructDoc)]
struct Point {
    /// The horizontal coordinate.
    x: i32,

    /// The vertical coordinate.
    y: i32,
}

let documentation = format!("{}", Point::document());
let expected = r#"<root> (Struct):
  * Field x (Integer):
    | The horizontal coordinate.
  * Field y (Integer):
    | The vertical coordinate.
"#;

assert_eq!(expected, documentation);

Deriving the trait

If the structdoc-derive feature is enabled (it is by default), it is possible to derive the trait on structs and enums. The text of documentation is extracted from the doc comments. Furthermore, it allows tweaking the implementation by attributes.

Because the primary aim of this crate is to provide user documentation for things fed to the application a lot of such things are handled by the serde crate, our derive can use both its own attributes and serde ones where it makes sense.

Ignoring fields and variants

They can be ignored by placing either #[doc(hidden)], #[serde(skip)], #[serde(skip_deserialize)] or #[structdoc(skip)] attributes on them.

Stubbing out implementations

If a field's type doesn't implement the trait or if recursing into it is not wanted (or maybe because the data structure is cyclic), it can be prefixed with the #[structdoc(leaf)] or #[structdoc(leag = "Type")] attribute. It'll provide trivial implementation without any explanation and the provided type in parenthesis, if one is provided.

Alternatively, a function fn() -> Documentation can be plugged in using the #[structdoc(with = "path::to::the_fn")]. That can return an arbitrary implementation.

Renaming things

The rename and rename_all attributes are available, both in serde and structdoc variants. They have the same meaning as withing serde.

Flattening

The #[serde(flatten)] and #[structdoc(flatten)] flattens structures inline.

Enum representations

The serde (and structdoc alternatives) of [tag representation] attributes are available.

Required methods

fn document() -> Documentation

Returns the documentation for the type.

Examples

use structdoc::StructDoc;

println!("Documentation: {}", Vec::<Option<String>>::document());
Loading content...

Implementations on Foreign Types

impl<T: StructDoc> StructDoc for Vec<T>[src]

impl<T: StructDoc> StructDoc for LinkedList<T>[src]

impl<T: StructDoc> StructDoc for VecDeque<T>[src]

impl<T: StructDoc> StructDoc for BinaryHeap<T>[src]

impl<T: StructDoc> StructDoc for BTreeSet<T>[src]

impl<T: StructDoc> StructDoc for [T; 1][src]

impl<T: StructDoc> StructDoc for [T; 2][src]

impl<T: StructDoc> StructDoc for [T; 3][src]

impl<T: StructDoc> StructDoc for [T; 4][src]

impl<T: StructDoc> StructDoc for [T; 5][src]

impl<T: StructDoc> StructDoc for [T; 6][src]

impl<T: StructDoc> StructDoc for [T; 7][src]

impl<T: StructDoc> StructDoc for [T; 8][src]

impl<T: StructDoc> StructDoc for [T; 9][src]

impl<T: StructDoc> StructDoc for [T; 10][src]

impl<T: StructDoc> StructDoc for [T; 11][src]

impl<T: StructDoc> StructDoc for [T; 12][src]

impl<T: StructDoc> StructDoc for [T; 13][src]

impl<T: StructDoc> StructDoc for [T; 14][src]

impl<T: StructDoc> StructDoc for [T; 15][src]

impl<T: StructDoc> StructDoc for [T; 16][src]

impl<T: StructDoc> StructDoc for [T; 17][src]

impl<T: StructDoc> StructDoc for [T; 18][src]

impl<T: StructDoc> StructDoc for [T; 19][src]

impl<T: StructDoc> StructDoc for [T; 20][src]

impl<T: StructDoc> StructDoc for [T; 21][src]

impl<T: StructDoc> StructDoc for [T; 22][src]

impl<T: StructDoc> StructDoc for [T; 23][src]

impl<T: StructDoc> StructDoc for [T; 24][src]

impl<T: StructDoc> StructDoc for [T; 25][src]

impl<T: StructDoc> StructDoc for [T; 26][src]

impl<T: StructDoc> StructDoc for [T; 27][src]

impl<T: StructDoc> StructDoc for [T; 28][src]

impl<T: StructDoc> StructDoc for [T; 29][src]

impl<T: StructDoc> StructDoc for [T; 30][src]

impl<T: StructDoc> StructDoc for [T; 31][src]

impl<T: StructDoc> StructDoc for [T; 32][src]

impl<T: StructDoc, S> StructDoc for HashSet<T, S>[src]

impl<T: StructDoc> StructDoc for [T][src]

impl<T: StructDoc> StructDoc for Option<T>[src]

impl<K: StructDoc, V: StructDoc, S> StructDoc for HashMap<K, V, S>[src]

impl<K: StructDoc, V: StructDoc> StructDoc for BTreeMap<K, V>[src]

impl<T: StructDoc> StructDoc for Arc<T>[src]

impl<T: StructDoc> StructDoc for Box<T>[src]

impl<T: StructDoc> StructDoc for Cell<T>[src]

impl<T: StructDoc> StructDoc for Mutex<T>[src]

impl<T: StructDoc> StructDoc for PhantomData<T>[src]

impl<T: StructDoc> StructDoc for Rc<T>[src]

impl<T: StructDoc> StructDoc for RefCell<T>[src]

impl<T: StructDoc> StructDoc for RwLock<T>[src]

impl<T: StructDoc> StructDoc for Wrapping<T>[src]

impl<T: StructDoc, '_> StructDoc for &'_ T[src]

impl<T: StructDoc, '_> StructDoc for &'_ mut T[src]

impl<T: Clone + StructDoc, '_> StructDoc for Cow<'_, T>[src]

impl StructDoc for u8[src]

impl StructDoc for u16[src]

impl StructDoc for u32[src]

impl StructDoc for u64[src]

impl StructDoc for u128[src]

impl StructDoc for usize[src]

impl StructDoc for NonZeroU8[src]

impl StructDoc for NonZeroU16[src]

impl StructDoc for NonZeroU32[src]

impl StructDoc for NonZeroU64[src]

impl StructDoc for NonZeroU128[src]

impl StructDoc for i8[src]

impl StructDoc for i16[src]

impl StructDoc for i32[src]

impl StructDoc for i64[src]

impl StructDoc for i128[src]

impl StructDoc for isize[src]

impl StructDoc for char[src]

impl StructDoc for str[src]

impl StructDoc for String[src]

impl StructDoc for CString[src]

impl StructDoc for CStr[src]

impl StructDoc for OsStr[src]

impl StructDoc for OsString[src]

impl StructDoc for bool[src]

impl StructDoc for ()[src]

impl StructDoc for f32[src]

impl StructDoc for f64[src]

impl StructDoc for Ipv4Addr[src]

impl StructDoc for Ipv6Addr[src]

impl StructDoc for IpAddr[src]

impl StructDoc for SocketAddrV4[src]

impl StructDoc for SocketAddrV6[src]

impl StructDoc for SocketAddr[src]

impl StructDoc for Path[src]

impl StructDoc for PathBuf[src]

impl StructDoc for Duration[src]

impl StructDoc for SystemTime[src]

impl StructDoc for Instant[src]

Loading content...

Implementors

Loading content...