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§
Sourcefn library(&self) -> &LazyHash<Library>
fn library(&self) -> &LazyHash<Library>
The standard library.
Can be created through Library::build()
.
Sourcefn source(&self, id: FileId) -> Result<Source, FileError>
fn source(&self, id: FileId) -> Result<Source, FileError>
Try to access the specified source file.
Sourcefn font(&self, index: usize) -> Option<Font>
fn font(&self, index: usize) -> Option<Font>
Try to access the font with the given index in the font book.
Sourcefn today(&self, offset: Option<i64>) -> Option<Datetime>
fn today(&self, offset: Option<i64>) -> Option<Datetime>
Get the current date.
If no offset is specified, the local date should be chosen. Otherwise, the UTC date should be chosen with the corresponding offset in hours.
If this function returns None
, Typst’s datetime
function will
return an error.