Trait webidl_utils::symbol::SymbolWithDocstring

source ·
pub trait SymbolWithDocstring {
    // Required methods
    fn docstring(&self) -> &str;
    fn has_docstring(&self) -> bool;
}
Expand description

A WebIDL symbol that may have a documentation string

Required Methods§

source

fn docstring(&self) -> &str

Returns a string literal with the starting whitespace removed. If the symbol has no docstring, it will return an empty string literal.

§Examples

The following examples compare the behavior and APIs of weedle2 and webidl-utils. To summarize:

  • weedle2:
    • Symbols that can contain a docstring will have type Option<Docstring>.
    • If there is no docstring, it will be None.
    • A parsed Docstring will have a non-normalized string. For example, if a docstring is written as /// This is an enum, the resulting string will be " This is an enum".
  • webidl-utils:
    • SymbolWithDocString will return a &str.
    • If there is no docstring, it will be "" (empty string literal).
    • It will normalize strings by removing the beginning whitespace.
use webidl_utils::symbol::SymbolWithDocstring;
use weedle::{EnumDefinition, Parse};

let (_, enum_def) = EnumDefinition::parse(
    r#"
        /// This is an enum
        enum Color { "red", "green", "blue" };
    "#)
    .expect("EnumDefinition parsed with an error");

// weedle2 behavior
assert_eq!(enum_def.docstring.clone().unwrap().0.as_str(), " This is an enum");

// webidl-utils behavior
assert_eq!(enum_def.docstring(), "This is an enum");
source

fn has_docstring(&self) -> bool

Implementations on Foreign Types§

source§

impl<'a> SymbolWithDocstring for AttributeNamespaceMember<'a>

source§

impl<'a> SymbolWithDocstring for CallbackInterfaceDefinition<'a>

source§

impl<'a> SymbolWithDocstring for ConstructorInterfaceMember<'a>

source§

impl<'a> SymbolWithDocstring for DictionaryDefinition<'a>

source§

impl<'a> SymbolWithDocstring for DictionaryMember<'a>

source§

impl<'a> SymbolWithDocstring for EnumDefinition<'a>

source§

impl<'a> SymbolWithDocstring for EnumVariant<'a>

source§

impl<'a> SymbolWithDocstring for InterfaceDefinition<'a>

source§

impl<'a> SymbolWithDocstring for NamespaceDefinition<'a>

source§

impl<'a> SymbolWithDocstring for OperationInterfaceMember<'a>

source§

impl<'a> SymbolWithDocstring for OperationNamespaceMember<'a>

Implementors§