Struct doku::json::AutoComments[][src]

pub struct AutoComments {
    pub array_size: bool,
    pub optional: bool,
}
Expand description

Determines which auto-comments - hints, so to say - should get displayed.

Sometimes Doku is able to automatically infer certain properties about a type and provide a dedicated hint such as “this field is optional”. This struct allows to configure whether you’d like for such comments to be printed or not.

Fields

array_size: bool

When set, displays hints for arrays of known sizes:

use doku::Document;

#[derive(Document)]
struct Person {
    friends: [String; 3],
}

let fmt = doku::json::Formatting {
    auto_comments: doku::json::AutoComments {
        array_size: true,
        ..Default::default()
    },
    ..Default::default()
};

let doc = doku::to_json_fmt::<Person>(&fmt);

doku::assert_doc!(r#"
  {
    // Must contain exactly 3 elements
    "friends": [
      "string",
      /* ... */
    ]
  }
"#, doc);
optional: bool

When set, displays hints for optional values:

use doku::Document;

#[derive(Document)]
struct Person {
    friend: Option<String>,
}

let fmt = doku::json::Formatting {
    auto_comments: doku::json::AutoComments {
        optional: true,
        ..Default::default()
    },
    ..Default::default()
};

let doc = doku::to_json_fmt::<Person>(&fmt);

doku::assert_doc!(r#"
  {
    // Optional
    "friend": "string"
  }
"#, doc);

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.