Skip to main content

PdfBlock

Enum PdfBlock 

Source
#[non_exhaustive]
pub enum PdfBlock {
Show 14 variants Heading { level: u8, text: String, source: SourceLocation, }, Paragraph { text: String, source: SourceLocation, }, List { ordered: bool, items: Vec<ListItem>, source: SourceLocation, }, Table { headers: Vec<String>, rows: Vec<Vec<String>>, source: SourceLocation, }, Image { data: ImageData, source: SourceLocation, }, Code { language: Option<String>, text: String, source: SourceLocation, }, Formula { latex: String, source: SourceLocation, }, PageBreak { source: SourceLocation, }, Footnote { reference_id: String, text: String, source: SourceLocation, }, TableCell { row_span: u32, col_span: u32, text: String, source: SourceLocation, }, BlockQuote { text: String, source: SourceLocation, }, HorizontalRule { source: SourceLocation, }, Link { url: String, text: String, source: SourceLocation, }, Unknown { raw: String, source: SourceLocation, },
}
Expand description

从 PDF 页面识别出的语义内容块。

#[non_exhaustive] 保证未来新增变体不会破坏下游代码。 消费方应始终包含通配分支(_ => ...)或使用 block_type 进行分发。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Heading

分级标题。

Fields

§level: u8

标题级别,范围为 1 到 6。

§text: String

标题文本。

§source: SourceLocation

源位置。

§

Paragraph

普通段落。

Fields

§text: String

段落文本。

§source: SourceLocation

源位置。

§

List

有序或无序列表。

Fields

§ordered: bool

是否为有序列表。

§items: Vec<ListItem>

列表项(支持嵌套)。

§source: SourceLocation

源位置。

§

Table

表格数据。

Fields

§headers: Vec<String>

表头。

§rows: Vec<Vec<String>>

表格行。

§source: SourceLocation

源位置。

§

Image

图片引用。

Fields

§data: ImageData

图片元数据。

§source: SourceLocation

源位置。

§

Code

代码块。

Fields

§language: Option<String>

代码语言标识(如 "rust""python")。

§text: String

代码文本。

§source: SourceLocation

源位置。

§

Formula

数学公式(LaTeX 语法)。

Fields

§latex: String

LaTeX 源码。

§source: SourceLocation

源位置。

§

PageBreak

分页符。

Fields

§source: SourceLocation

源位置。

§

Footnote

脚注。

Fields

§reference_id: String

脚注引用标识。

§text: String

脚注正文。

§source: SourceLocation

源位置。

§

TableCell

表格单元格(细粒度识别)。

Fields

§row_span: u32

行跨度。

§col_span: u32

列跨度。

§text: String

单元格文本。

§source: SourceLocation

源位置。

§

BlockQuote

引用块。

Fields

§text: String

引用文本。

§source: SourceLocation

源位置。

§

HorizontalRule

水平分隔线。

Fields

§source: SourceLocation

源位置。

超链接。

Fields

§url: String

链接地址。

§text: String

链接显示文本。

§source: SourceLocation

源位置。

§

Unknown

无法识别的内容。

Fields

§raw: String

原始文本。

§source: SourceLocation

源位置。

Implementations§

Source§

impl PdfBlock

Source

pub fn heading( level: u8, text: impl Into<String>, source: SourceLocation, ) -> Self

创建分级标题。

Source

pub fn paragraph(text: impl Into<String>, source: SourceLocation) -> Self

创建普通段落。

Source

pub fn list(ordered: bool, items: Vec<ListItem>, source: SourceLocation) -> Self

创建有序或无序列表。

Source

pub fn table( headers: Vec<String>, rows: Vec<Vec<String>>, source: SourceLocation, ) -> Self

创建表格。

Source

pub fn image(data: ImageData, source: SourceLocation) -> Self

创建图片引用。

Source

pub fn code(text: impl Into<String>, source: SourceLocation) -> Self

创建代码块。

Source

pub fn code_with_language( language: impl Into<String>, text: impl Into<String>, source: SourceLocation, ) -> Self

创建带语言标识的代码块。

Source

pub fn formula(latex: impl Into<String>, source: SourceLocation) -> Self

创建数学公式。

Source

pub const fn page_break(source: SourceLocation) -> Self

创建分页符。

Source

pub fn footnote( ref_id: impl Into<String>, text: impl Into<String>, source: SourceLocation, ) -> Self

创建脚注。

Source

pub fn table_cell( row_span: u32, col_span: u32, text: impl Into<String>, source: SourceLocation, ) -> Self

创建表格单元格。

Source

pub fn block_quote(text: impl Into<String>, source: SourceLocation) -> Self

创建引用块。

Source

pub const fn horizontal_rule(source: SourceLocation) -> Self

创建水平分隔线。

创建超链接。

Source

pub fn unknown(raw: impl Into<String>, source: SourceLocation) -> Self

创建无法识别的内容。

Source

pub const fn source(&self) -> &SourceLocation

返回内容块的源位置。

Source

pub const fn block_type(&self) -> PdfBlockType

返回内容块的语义分类。

§Examples
use easypdf_core::{PdfBlock, PdfBlockType, SourceLocation};
use easypdf_core::PageIndex;

let loc = SourceLocation::new(PageIndex::new(0), 1.0);
let block = PdfBlock::heading(1, "Title", loc);
assert_eq!(block.block_type(), PdfBlockType::Heading);

Trait Implementations§

Source§

impl Clone for PdfBlock

Source§

fn clone(&self) -> PdfBlock

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 PdfBlock

Source§

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

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

impl PartialEq for PdfBlock

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PdfBlock

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> From<T> for T

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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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