Skip to main content

UnitContext

Struct UnitContext 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: TextMap

Subtitle 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

Source

pub fn with_role(self, role: impl Into<Option<Role>>) -> UnitContext

Sets (or with None clears) the structural role.

Source

pub fn with_level(self, level: impl Into<Option<u8>>) -> UnitContext

Sets (or clears) the heading level.

Source

pub fn role(&self) -> Option<Role>

The structural role, when known.

Source

pub fn level(&self) -> Option<u8>

The heading level, when known.

Source

pub fn set_role(&mut self, role: impl Into<Option<Role>>)

Sets (or with None clears) the structural role, in place.

Source

pub fn set_level(&mut self, level: impl Into<Option<u8>>)

Sets (or clears) the heading level, in place.

Source

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

Source

pub fn new() -> UnitContext

An empty context.

Source

pub fn with_kind(self, kind: impl IntoOptionString) -> UnitContext

Sets (or with None clears) what the unit is (“heading”, “cell”, …).

Source

pub fn with_style(self, style: impl IntoOptionString) -> UnitContext

Sets (or clears) the style or element name.

Source

pub fn with_key(self, key: impl IntoOptionString) -> UnitContext

Sets (or clears) the resource key or path.

Source

pub fn with_heading(self, heading: impl IntoOptionString) -> UnitContext

Sets (or clears) the nearest heading.

Source

pub fn with_location(self, location: impl IntoOptionString) -> UnitContext

Sets (or clears) the readable location.

Source

pub fn with_max_len(self, max_len: Option<usize>) -> UnitContext

Sets (or clears) the maximum length in characters.

Source

pub fn with_notes(self, notes: Vec<String>) -> UnitContext

Replaces the notes.

Source

pub fn with_extra(self, extra: impl Into<TextMap>) -> UnitContext

Replaces the extras (a TextMap, or a BTreeMap<String, String>).

Source

pub fn kind(&self) -> Option<&str>

What the unit is (“heading”, “cell”, …).

Source

pub fn style(&self) -> Option<&str>

The style or element name.

Source

pub fn key(&self) -> Option<&str>

The resource key or path.

Source

pub fn heading(&self) -> Option<&str>

The nearest heading.

Source

pub fn location(&self) -> Option<&str>

The readable location.

Source

pub fn set_kind(&mut self, kind: impl IntoOptionString)

Sets (or with None clears) what the unit is, in place.

Source

pub fn set_style(&mut self, style: impl IntoOptionString)

Sets (or clears) the style or element name, in place.

Source

pub fn set_key(&mut self, key: impl IntoOptionString)

Sets (or clears) the resource key or path, in place.

Source

pub fn set_heading(&mut self, heading: impl IntoOptionString)

Sets (or clears) the nearest heading, in place.

Source

pub fn set_location(&mut self, location: impl IntoOptionString)

Sets (or clears) the readable location, in place.

Source

pub fn extra(&self) -> &TextMap

The extras, read-only.

Source

pub fn extra_mut(&mut self) -> &mut TextMap

The extras, to change in place.

Source

pub fn set_extra(&mut self, extra: impl Into<TextMap>)

Replaces the extras (a TextMap, or a BTreeMap<String, String>).

Trait Implementations§

Source§

impl Clone for UnitContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnitContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UnitContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for UnitContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for UnitContext

Source§

impl PartialEq for UnitContext

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for UnitContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for UnitContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.