Struct bilingual::md::Md

source ·
pub struct Md<'e> { /* private fields */ }

Implementations§

source§

impl<'e> Md<'e>

source

pub fn new(md: &'e str) -> Self

构造函数。

source

pub fn chars_paragraph(&mut self, limit: usize) -> impl Iterator<Item = &str>

以字符数量分割段落批次。 分批策略如下:

  • 当返回 Some 时,意味着返回完整的段落,且至少返回一个段落;

  • 当返回 None 时,意味着已经返回所有段落。

  • 每次返回的段落有两种情况:

    1. 不多于 limit 字符大小的完整段落(至少一个完整段落);
    2. 字符大小超过 limit 的一个段落。
注意
  • 本方法比 bytes_paragraph 多做了一件事:计算和记录每个段落的字符长度。
  • 需要每个段落的字符或字节长度,请再调用: charsbytes
  • 此方法可以多次调用:这在需要不同 limit 的分批时很有用。但是注意:
    • 调用 extract 之后再调用此方法会重复提取段落;
    • 调用 bytes_paragraph 之后再调用此方法会重复提取段落;
    • 多次调用此方法不会重复提取段落;
source

pub fn bytes_paragraph(&mut self, limit: usize) -> impl Iterator<Item = &str>

提取原文的段落文本,并返回以字节数量分割的段落批次。 分批策略如下:

  • 当返回 Some 时,意味着返回完整的段落,且至少返回一个段落;

  • 当返回 None 时,意味着已经返回所有段落。

  • 每次返回的段落有两种情况:

    1. 不多于 limit 字节大小的完整段落(至少一个完整段落);
    2. 字节大小超过 limit 的一个段落。
注意
  • 本方法比 extract 多做了一件事:计算和记录每个段落的字节长度。
  • 需要每个段落的字节长度,请调用:bytes
  • 此方法可以多次调用:这在需要不同 limit 的分批时很有用。但是注意:
    • 调用 extract 之后再调用此方法会重复提取段落;
    • 调用 chars_paragraph 之后再调用此方法不会重复提取段落;
    • 多次调用此方法不会重复提取段落;
source

pub fn extract(&mut self) -> &str

提取原文的段落文本。

注意
  • 此方法可以多次调用:
    • 调用 bytes_paragraph 之后再调用此方法不会重复提取段落;
    • 调用 chars_paragraph 之后再调用此方法不会重复提取段落;
    • 多次调用此方法不会重复提取段落;

TODO: 尽可能保存原样式/结构

source

pub fn paragraphs(&self) -> &str

浏览提取后的原文段落文本。

source

pub fn bytes(&self) -> impl Iterator<Item = usize> + '_

提取的每个原文段落的字节数。

source

pub fn chars(&self) -> impl Iterator<Item = usize> + '_

提取的每个原文段落的字符数。

source

pub fn chars_bytes_range(
    &self
) -> impl Iterator<Item = (usize, usize, Range<usize>)> + '_

提取的每个原文段落的字符数、字节数和字节范围。

source

pub fn done(self, paragraph: impl Iterator<Item = &'e str>) -> String

完成并返回写入翻译内容。参数 paragraph 为按段落翻译的译文

Trait Implementations§

source§

impl<'e> Debug for Md<'e>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'e> RefUnwindSafe for Md<'e>

§

impl<'e> Send for Md<'e>

§

impl<'e> Sync for Md<'e>

§

impl<'e> Unpin for Md<'e>

§

impl<'e> UnwindSafe for Md<'e>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
    S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more