Skip to main content

GeneratedFormatCache

Struct GeneratedFormatCache 

Source
pub struct GeneratedFormatCache { /* private fields */ }
Expand description

A cached snapshot of a generated engine format image for repeated instantiation.

Implementations§

Source§

impl GeneratedFormatCache

Source

pub fn empty() -> Self

Returns an empty format cache with no initialized state.

Source

pub fn initialized(profile: EngineProfile) -> Self

Initializes a generated engine once and snapshots it as a reusable format cache.

Examples found in repository?
examples/pack_native_format.rs (line 95)
72fn main() -> ExitCode {
73    let Some(output) = output_path() else {
74        eprintln!("usage: pack_native_format <output path>");
75        return ExitCode::FAILURE;
76    };
77    let Some(texmf_root) = find_texmf_root() else {
78        eprintln!("cannot find a texmf-dist ls-R index");
79        return ExitCode::FAILURE;
80    };
81    let Some(texmf) = TexmfResources::from_root(texmf_root) else {
82        eprintln!("cannot load the texmf-dist ls-R index");
83        return ExitCode::FAILURE;
84    };
85    let texmf = Arc::new(texmf);
86
87    let latex = match texmf.read("latex.ltx", ResourceKind::TexInput) {
88        Ok(resource) => resource.bytes,
89        Err(error) => {
90            eprintln!("cannot read latex.ltx: {error:?}");
91            return ExitCode::FAILURE;
92        }
93    };
94
95    let cache = GeneratedFormatCache::initialized(pe::EngineProfile::xetex());
96    let mut engine = cache
97        .instantiate(
98            pe::EngineProfile::xetex(),
99            GeneratedResourceProvider::new(&*texmf),
100        )
101        .with_font_platform(GeneratedFontSystemAdapter::new(NativeFontSystem::new(
102            texmf.clone(),
103        )));
104
105    if !engine.begin_primary_input("latex.ltx", latex) {
106        eprintln!("failed to begin latex.ltx");
107        return ExitCode::FAILURE;
108    }
109    engine.run_format_initialization();
110    if !engine.begin_primary_input("preamble.tex", PREAMBLE.to_vec()) {
111        eprintln!("failed to begin preamble");
112        return ExitCode::FAILURE;
113    }
114    engine.run_format_initialization();
115
116    engine.finalize_trie();
117    let format_bytes = GeneratedFormatCache::from_engine(&engine).to_bytes();
118    let font_table = engine.native_font_table();
119    let packaged = mathtex_engine::generated::pack_packaged_format(&format_bytes, &font_table);
120    if let Err(error) = std::fs::write(&output, packaged) {
121        eprintln!("cannot write {}: {error}", output.display());
122        return ExitCode::FAILURE;
123    }
124    ExitCode::SUCCESS
125}
Source

pub fn from_engine(engine: &PortableTexEngine<'_>) -> Self

Snapshots the engine’s current format state into a reusable cache.

Examples found in repository?
examples/pack_native_format.rs (line 117)
72fn main() -> ExitCode {
73    let Some(output) = output_path() else {
74        eprintln!("usage: pack_native_format <output path>");
75        return ExitCode::FAILURE;
76    };
77    let Some(texmf_root) = find_texmf_root() else {
78        eprintln!("cannot find a texmf-dist ls-R index");
79        return ExitCode::FAILURE;
80    };
81    let Some(texmf) = TexmfResources::from_root(texmf_root) else {
82        eprintln!("cannot load the texmf-dist ls-R index");
83        return ExitCode::FAILURE;
84    };
85    let texmf = Arc::new(texmf);
86
87    let latex = match texmf.read("latex.ltx", ResourceKind::TexInput) {
88        Ok(resource) => resource.bytes,
89        Err(error) => {
90            eprintln!("cannot read latex.ltx: {error:?}");
91            return ExitCode::FAILURE;
92        }
93    };
94
95    let cache = GeneratedFormatCache::initialized(pe::EngineProfile::xetex());
96    let mut engine = cache
97        .instantiate(
98            pe::EngineProfile::xetex(),
99            GeneratedResourceProvider::new(&*texmf),
100        )
101        .with_font_platform(GeneratedFontSystemAdapter::new(NativeFontSystem::new(
102            texmf.clone(),
103        )));
104
105    if !engine.begin_primary_input("latex.ltx", latex) {
106        eprintln!("failed to begin latex.ltx");
107        return ExitCode::FAILURE;
108    }
109    engine.run_format_initialization();
110    if !engine.begin_primary_input("preamble.tex", PREAMBLE.to_vec()) {
111        eprintln!("failed to begin preamble");
112        return ExitCode::FAILURE;
113    }
114    engine.run_format_initialization();
115
116    engine.finalize_trie();
117    let format_bytes = GeneratedFormatCache::from_engine(&engine).to_bytes();
118    let font_table = engine.native_font_table();
119    let packaged = mathtex_engine::generated::pack_packaged_format(&format_bytes, &font_table);
120    if let Err(error) = std::fs::write(&output, packaged) {
121        eprintln!("cannot write {}: {error}", output.display());
122        return ExitCode::FAILURE;
123    }
124    ExitCode::SUCCESS
125}
Source

pub fn from_engine_owned(engine: PortableTexEngine<'_>) -> Self

Consumes an engine into a format cache by moving its state in place, avoiding a full clone.

Source

pub fn image(&self) -> &PortableFormatImage

Returns a reference to the raw format image.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

Serializes the format image to a buffer valid for the same build target only.

Examples found in repository?
examples/pack_native_format.rs (line 117)
72fn main() -> ExitCode {
73    let Some(output) = output_path() else {
74        eprintln!("usage: pack_native_format <output path>");
75        return ExitCode::FAILURE;
76    };
77    let Some(texmf_root) = find_texmf_root() else {
78        eprintln!("cannot find a texmf-dist ls-R index");
79        return ExitCode::FAILURE;
80    };
81    let Some(texmf) = TexmfResources::from_root(texmf_root) else {
82        eprintln!("cannot load the texmf-dist ls-R index");
83        return ExitCode::FAILURE;
84    };
85    let texmf = Arc::new(texmf);
86
87    let latex = match texmf.read("latex.ltx", ResourceKind::TexInput) {
88        Ok(resource) => resource.bytes,
89        Err(error) => {
90            eprintln!("cannot read latex.ltx: {error:?}");
91            return ExitCode::FAILURE;
92        }
93    };
94
95    let cache = GeneratedFormatCache::initialized(pe::EngineProfile::xetex());
96    let mut engine = cache
97        .instantiate(
98            pe::EngineProfile::xetex(),
99            GeneratedResourceProvider::new(&*texmf),
100        )
101        .with_font_platform(GeneratedFontSystemAdapter::new(NativeFontSystem::new(
102            texmf.clone(),
103        )));
104
105    if !engine.begin_primary_input("latex.ltx", latex) {
106        eprintln!("failed to begin latex.ltx");
107        return ExitCode::FAILURE;
108    }
109    engine.run_format_initialization();
110    if !engine.begin_primary_input("preamble.tex", PREAMBLE.to_vec()) {
111        eprintln!("failed to begin preamble");
112        return ExitCode::FAILURE;
113    }
114    engine.run_format_initialization();
115
116    engine.finalize_trie();
117    let format_bytes = GeneratedFormatCache::from_engine(&engine).to_bytes();
118    let font_table = engine.native_font_table();
119    let packaged = mathtex_engine::generated::pack_packaged_format(&format_bytes, &font_table);
120    if let Err(error) = std::fs::write(&output, packaged) {
121        eprintln!("cannot write {}: {error}", output.display());
122        return ExitCode::FAILURE;
123    }
124    ExitCode::SUCCESS
125}
Source

pub fn from_bytes(bytes: &[u8]) -> Option<Self>

Deserializes a format cache from a buffer produced by Self::to_bytes.

Source

pub fn from_static_bytes(bytes: &'static [u8]) -> Option<Self>

Borrows a static serialized image without allocating or copying its contents.

Source

pub fn instantiate<'resources, R>( &self, profile: EngineProfile, resources: R, ) -> PortableTexEngine<'resources>
where R: ResourceProvider + 'resources,

Creates a new engine instance from this cached format image.

Examples found in repository?
examples/pack_native_format.rs (lines 97-100)
72fn main() -> ExitCode {
73    let Some(output) = output_path() else {
74        eprintln!("usage: pack_native_format <output path>");
75        return ExitCode::FAILURE;
76    };
77    let Some(texmf_root) = find_texmf_root() else {
78        eprintln!("cannot find a texmf-dist ls-R index");
79        return ExitCode::FAILURE;
80    };
81    let Some(texmf) = TexmfResources::from_root(texmf_root) else {
82        eprintln!("cannot load the texmf-dist ls-R index");
83        return ExitCode::FAILURE;
84    };
85    let texmf = Arc::new(texmf);
86
87    let latex = match texmf.read("latex.ltx", ResourceKind::TexInput) {
88        Ok(resource) => resource.bytes,
89        Err(error) => {
90            eprintln!("cannot read latex.ltx: {error:?}");
91            return ExitCode::FAILURE;
92        }
93    };
94
95    let cache = GeneratedFormatCache::initialized(pe::EngineProfile::xetex());
96    let mut engine = cache
97        .instantiate(
98            pe::EngineProfile::xetex(),
99            GeneratedResourceProvider::new(&*texmf),
100        )
101        .with_font_platform(GeneratedFontSystemAdapter::new(NativeFontSystem::new(
102            texmf.clone(),
103        )));
104
105    if !engine.begin_primary_input("latex.ltx", latex) {
106        eprintln!("failed to begin latex.ltx");
107        return ExitCode::FAILURE;
108    }
109    engine.run_format_initialization();
110    if !engine.begin_primary_input("preamble.tex", PREAMBLE.to_vec()) {
111        eprintln!("failed to begin preamble");
112        return ExitCode::FAILURE;
113    }
114    engine.run_format_initialization();
115
116    engine.finalize_trie();
117    let format_bytes = GeneratedFormatCache::from_engine(&engine).to_bytes();
118    let font_table = engine.native_font_table();
119    let packaged = mathtex_engine::generated::pack_packaged_format(&format_bytes, &font_table);
120    if let Err(error) = std::fs::write(&output, packaged) {
121        eprintln!("cannot write {}: {error}", output.display());
122        return ExitCode::FAILURE;
123    }
124    ExitCode::SUCCESS
125}

Trait Implementations§

Source§

impl Clone for GeneratedFormatCache

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 GeneratedFormatCache

Source§

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

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

impl Default for GeneratedFormatCache

Source§

fn default() -> Self

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

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