Trait TypstWorld
pub trait TypstWorld: Send + Sync {
// Required methods
fn library(&self) -> &LazyHash<Library>;
fn book(&self) -> &LazyHash<FontBook>;
fn main(&self) -> FileId;
fn source(&self, id: FileId) -> Result<Source, FileError>;
fn file(&self, id: FileId) -> Result<Bytes, FileError>;
fn font(&self, index: usize) -> Option<Font>;
fn today(&self, offset: Option<i64>) -> Option<Datetime>;
}
Expand description
The environment in which typesetting occurs.
All loading functions (main
, source
, file
, font
) should perform
internal caching so that they are relatively cheap on repeated invocations
with the same argument. [Source
], Bytes
, and Font
are
all reference-counted and thus cheap to clone.
The compiler doesn’t do the caching itself because the world has much more
information on when something can change. For example, fonts typically don’t
change and can thus even be cached across multiple compilations (for
long-running applications like typst watch
). Source files on the other
hand can change and should thus be cleared after each compilation. Advanced
clients like language servers can also retain the source files and
edit them in-place to benefit from better incremental
performance.
Required Methods§
fn library(&self) -> &LazyHash<Library>
fn library(&self) -> &LazyHash<Library>
The standard library.
Can be created through Library::build()
.