#[non_exhaustive]pub struct CodeData {
pub open: Option<String>,
pub close: Option<String>,
pub standalone: Option<String>,
pub label: Option<String>,
pub ty: Option<CodeType>,
pub attrs: TextMap,
}Expand description
The original markup of one inline code, kept so the writer can reproduce it.
A paired code fills open and close; a standalone code fills standalone. Build it with
CodeData::paired, CodeData::standalone or CodeData::new and the with_* methods.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.open: Option<String>The opening markup of a paired code.
close: Option<String>The closing markup of a paired code.
standalone: Option<String>The markup of a standalone code.
label: Option<String>Human label for the tag chip, e.g. “bold”, “link”.
ty: Option<CodeType>What the code is (bold, link, field…), when the format knows (BILI-118). JSON key type, left out when
unset. Extractors fill it; writers never read it. Unset under the LocOS profile.
attrs: TextMapFacts about the code, keyed per type (see CodeType::attr_keys): href and title for a link, …
Left out of the JSON when empty. Unset under the LocOS profile.
Implementations§
Source§impl CodeData
impl CodeData
Sourcepub fn paired(open: impl Into<String>, close: impl Into<String>) -> CodeData
pub fn paired(open: impl Into<String>, close: impl Into<String>) -> CodeData
A paired code’s markup.
Sourcepub fn standalone(markup: impl Into<String>) -> CodeData
pub fn standalone(markup: impl Into<String>) -> CodeData
A standalone code’s markup.
Sourcepub fn with_open(self, open: impl IntoOptionString) -> CodeData
pub fn with_open(self, open: impl IntoOptionString) -> CodeData
Sets (or with None clears) the opening markup.
Sourcepub fn with_close(self, close: impl IntoOptionString) -> CodeData
pub fn with_close(self, close: impl IntoOptionString) -> CodeData
Sets (or clears) the closing markup.
Sourcepub fn with_standalone(self, standalone: impl IntoOptionString) -> CodeData
pub fn with_standalone(self, standalone: impl IntoOptionString) -> CodeData
Sets (or clears) the standalone markup.
Sourcepub fn with_label(self, label: impl IntoOptionString) -> CodeData
pub fn with_label(self, label: impl IntoOptionString) -> CodeData
Sets (or clears) the chip label.
Sourcepub fn open_markup(&self) -> Option<&str>
pub fn open_markup(&self) -> Option<&str>
The opening markup of a paired code. (open_markup, not open, to match CodeData::standalone_markup,
whose plain name is taken by the CodeData::standalone constructor.)
Sourcepub fn close_markup(&self) -> Option<&str>
pub fn close_markup(&self) -> Option<&str>
The closing markup of a paired code.
Sourcepub fn standalone_markup(&self) -> Option<&str>
pub fn standalone_markup(&self) -> Option<&str>
The markup of a standalone code.
Sourcepub fn set_open(&mut self, open: impl IntoOptionString)
pub fn set_open(&mut self, open: impl IntoOptionString)
Sets (or with None clears) the opening markup in place.
Sourcepub fn set_close(&mut self, close: impl IntoOptionString)
pub fn set_close(&mut self, close: impl IntoOptionString)
Sets (or clears) the closing markup in place.
Sourcepub fn set_standalone(&mut self, standalone: impl IntoOptionString)
pub fn set_standalone(&mut self, standalone: impl IntoOptionString)
Sets (or clears) the standalone markup in place.
Sourcepub fn set_label(&mut self, label: impl IntoOptionString)
pub fn set_label(&mut self, label: impl IntoOptionString)
Sets (or clears) the chip label in place.
Source§impl CodeData
impl CodeData
Sourcepub fn with_code_type(self, ty: Option<CodeType>) -> CodeData
pub fn with_code_type(self, ty: Option<CodeType>) -> CodeData
Sets (or clears) the code type.
Sourcepub fn with_attr(self, key: &str, value: impl Into<Box<str>>) -> CodeData
pub fn with_attr(self, key: &str, value: impl Into<Box<str>>) -> CodeData
Sets one attribute (href, field, …); an empty value is not stored.
Sourcepub fn set_code_type(&mut self, ty: Option<CodeType>)
pub fn set_code_type(&mut self, ty: Option<CodeType>)
Sets (or with None clears) the code type in place.
Sourcepub fn attrs(&self) -> &TextMap
pub fn attrs(&self) -> &TextMap
The code’s attributes (keys per CodeType::attr_keys).
Sourcepub fn set_attr(&mut self, key: &str, value: impl Into<Box<str>>)
pub fn set_attr(&mut self, key: &str, value: impl Into<Box<str>>)
Sets one attribute in place; an empty value removes it instead.
Sourcepub fn clear_typing(&mut self)
pub fn clear_typing(&mut self)
Clears the type and the attributes (what the LocOS profile does to every code).