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§
sourcefn docstring(&self) -> &str
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"
.
- Symbols that can contain a docstring will have type
- 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");