Skip to main content

Segment

Struct Segment 

Source
#[non_exhaustive]
pub struct Segment { pub id: String, pub source: Vec<Inline>, pub target: Vec<Inline>, pub state: SegState, pub origin: Option<Origin>, pub empty_target: bool, }
Expand description

One translatable piece of a unit: its source, and its target once there is one. Build it with Segment::new and the with_* methods.

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.
§id: String

Unique within the document: <unit id> when the unit has one segment, else <unit id>#<n> (1-based).

§source: Vec<Inline>

The source text with its inline codes.

§target: Vec<Inline>

Empty = untranslated, unless empty_target says the translation is empty on purpose (see below).

§state: SegState

Where the segment is in its life (new, draft, translated, …).

§origin: Option<Origin>

Where the target came from. None for monolingual files and for targets nobody labelled.

§empty_target: bool

Translated to nothing on purpose. The empty-translation rule: a segment with an empty target is untranslated and the writer keeps its source text, unless empty_target is true; then the segment counts as translated (Segment::has_target) and the writer writes nothing for it. Document::set_target_empty sets it; Document::set_target with any target clears it. Left out of the JSON when false. (Localization OS writes an empty target as an empty value or paragraph: its adapter sets this flag for an empty LocOS target.)

Implementations§

Source§

impl Segment

Source

pub fn new(id: impl Into<String>, source: Vec<Inline>) -> Segment

An untranslated segment (no target, state New, no origin).

Source

pub fn has_target(&self) -> bool

True when the segment is translated: it has a target, or it was translated to nothing on purpose.

Source

pub fn output(&self) -> &[Inline]

The text to write: the target, nothing for an empty translation, or the source when untranslated.

Source

pub fn with_empty_target(self, empty_target: bool) -> Segment

Marks (or unmarks) the segment as translated to nothing on purpose; marking clears the target.

Source

pub fn with_target(self, target: Vec<Inline>) -> Segment

Sets the target as it is (no tag check: use Document::set_target for edits).

Source

pub fn with_state(self, state: SegState) -> Segment

Sets the state.

Source

pub fn with_origin(self, origin: impl Into<Option<Origin>>) -> Segment

Sets (or with None clears) where the target came from.

Trait Implementations§

Source§

impl Clone for Segment

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 Segment

Source§

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

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

impl<'de> Deserialize<'de> for Segment

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 Segment

Source§

impl PartialEq for Segment

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 Segment

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 Segment

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.