#[non_exhaustive]pub struct UnitContext {
pub kind: Option<String>,
pub style: Option<String>,
pub key: Option<String>,
pub heading: Option<String>,
pub location: Option<String>,
pub max_len: Option<usize>,
pub notes: Vec<String>,
pub extra: TextMap,
pub role: Option<Role>,
pub level: Option<u8>,
}Expand description
What helps a translator, an AI lane or a preview understand a unit. Build it with UnitContext::new and the
with_* methods; extra takes anything without a field of its own.
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.kind: Option<String>What the unit is: “heading”, “paragraph”, “list-item”, “cell”, “button”, “title”, “alt”, “key”, “subtitle”, … Free text; parsers use the most specific word they know.
style: Option<String>Style or element name as the file has it, e.g. “Heading 2”, “h2”, “td”.
key: Option<String>Resource key or path for key/value formats (JSON pointer, PO msgctxt + msgid, subtitle number).
heading: Option<String>Nearest heading text above the unit, when the format has headings.
location: Option<String>Location in the original, readable: word/document.xml paragraph 12, /html/body/main/p[3].
max_len: Option<usize>Maximum length in characters, when the file states one.
notes: Vec<String>Comments or notes attached in the file (translator comments, PO comments, DOCX comments).
extra: TextMapSubtitle timing and similar extras the editor may show.
role: Option<Role>The unit’s structural role in the document (a heading, a header, a speaker note, …), when the format
knows it. Left out of JSON when unset. Not filled under the locos profile.
level: Option<u8>The outline level for Role::Heading (1 for a top-level heading). Left out of JSON when unset.
Implementations§
Source§impl UnitContext
impl UnitContext
Sourcepub fn with_role(self, role: impl Into<Option<Role>>) -> UnitContext
pub fn with_role(self, role: impl Into<Option<Role>>) -> UnitContext
Sets (or with None clears) the structural role.
Sourcepub fn with_level(self, level: impl Into<Option<u8>>) -> UnitContext
pub fn with_level(self, level: impl Into<Option<u8>>) -> UnitContext
Sets (or clears) the heading level.
Sourcepub fn set_role(&mut self, role: impl Into<Option<Role>>)
pub fn set_role(&mut self, role: impl Into<Option<Role>>)
Sets (or with None clears) the structural role, in place.
Sourcepub fn set_level(&mut self, level: impl Into<Option<u8>>)
pub fn set_level(&mut self, level: impl Into<Option<u8>>)
Sets (or clears) the heading level, in place.
Sourcepub fn set_heading_role(&mut self, level: u8)
pub fn set_heading_role(&mut self, level: u8)
Sets the role Role::Heading and its level in one call (a level of 0 is stored as unset).
Source§impl UnitContext
impl UnitContext
Sourcepub fn new() -> UnitContext
pub fn new() -> UnitContext
An empty context.
Sourcepub fn with_kind(self, kind: impl IntoOptionString) -> UnitContext
pub fn with_kind(self, kind: impl IntoOptionString) -> UnitContext
Sets (or with None clears) what the unit is (“heading”, “cell”, …).
Sourcepub fn with_style(self, style: impl IntoOptionString) -> UnitContext
pub fn with_style(self, style: impl IntoOptionString) -> UnitContext
Sets (or clears) the style or element name.
Sourcepub fn with_key(self, key: impl IntoOptionString) -> UnitContext
pub fn with_key(self, key: impl IntoOptionString) -> UnitContext
Sets (or clears) the resource key or path.
Sourcepub fn with_heading(self, heading: impl IntoOptionString) -> UnitContext
pub fn with_heading(self, heading: impl IntoOptionString) -> UnitContext
Sets (or clears) the nearest heading.
Sourcepub fn with_location(self, location: impl IntoOptionString) -> UnitContext
pub fn with_location(self, location: impl IntoOptionString) -> UnitContext
Sets (or clears) the readable location.
Sourcepub fn with_max_len(self, max_len: Option<usize>) -> UnitContext
pub fn with_max_len(self, max_len: Option<usize>) -> UnitContext
Sets (or clears) the maximum length in characters.
Sourcepub fn with_notes(self, notes: Vec<String>) -> UnitContext
pub fn with_notes(self, notes: Vec<String>) -> UnitContext
Replaces the notes.
Sourcepub fn with_extra(self, extra: impl Into<TextMap>) -> UnitContext
pub fn with_extra(self, extra: impl Into<TextMap>) -> UnitContext
Replaces the extras (a TextMap, or a BTreeMap<String, String>).
Sourcepub fn set_kind(&mut self, kind: impl IntoOptionString)
pub fn set_kind(&mut self, kind: impl IntoOptionString)
Sets (or with None clears) what the unit is, in place.
Sourcepub fn set_style(&mut self, style: impl IntoOptionString)
pub fn set_style(&mut self, style: impl IntoOptionString)
Sets (or clears) the style or element name, in place.
Sourcepub fn set_key(&mut self, key: impl IntoOptionString)
pub fn set_key(&mut self, key: impl IntoOptionString)
Sets (or clears) the resource key or path, in place.
Sourcepub fn set_heading(&mut self, heading: impl IntoOptionString)
pub fn set_heading(&mut self, heading: impl IntoOptionString)
Sets (or clears) the nearest heading, in place.
Sourcepub fn set_location(&mut self, location: impl IntoOptionString)
pub fn set_location(&mut self, location: impl IntoOptionString)
Sets (or clears) the readable location, in place.