Skip to content

How to displaydoc an Option? #39

@sffc

Description

@sffc

How can I write a displaydoc impl for the following struct?

#[displaydoc("{kind}: {str_context}")]
pub struct DataError {
    /// Broad category of the error.
    pub kind: DataErrorKind,

    /// Additional context, if available.
    pub str_context: Option<&'static str>,
}

This errors out with:

`std::option::Option<&str>` cannot be formatted with the default formatter

What I would like is to make an error that contains ": {str_context}" when Some and nothing when None.

Do I need to manually implement Display, or can I use displaydoc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions