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<Duration>) -> 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 file location as a source file.
Sourcefn file(&self, id: FileId) -> Result<Bytes, FileError>
fn file(&self, id: FileId) -> Result<Bytes, FileError>
Try to access the specified file.
For file locations for which source succeeds, this
should also succeed. The Bytes can be cheaply created as a view into
an existing Source through Bytes::from_string.
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.
Note that the index is not guaranteed to be in bounds of the font book
returned by this world’s book() function. This is the case because
this function may be invoked with indices from an outdated or different
font book during incremental compilation validation.
Trait Implementations§
Source§impl<'__comemo_dynamic> Track for dyn World + '__comemo_dynamic
impl<'__comemo_dynamic> Track for dyn World + '__comemo_dynamic
Source§type Call = __ComemoCall
type Call = __ComemoCall
Source§fn call(&self, call: &<dyn World + '__comemo_dynamic as Track>::Call) -> u128
fn call(&self, call: &<dyn World + '__comemo_dynamic as Track>::Call) -> u128
Source§fn call_mut(&mut self, call: &<dyn World + '__comemo_dynamic as Track>::Call)
fn call_mut(&mut self, call: &<dyn World + '__comemo_dynamic as Track>::Call)
Source§fn track_mut(&mut self) -> TrackedMut<'_, Self>
fn track_mut(&mut self) -> TrackedMut<'_, Self>
Source§fn track_with<'a>(
&'a self,
sink: &'a dyn Sink<Call = Self::Call>,
) -> Tracked<'a, Self>
fn track_with<'a>( &'a self, sink: &'a dyn Sink<Call = Self::Call>, ) -> Tracked<'a, Self>
Source§fn track_mut_with<'a>(
&'a mut self,
sink: &'a dyn Sink<Call = Self::Call>,
) -> TrackedMut<'a, Self>
fn track_mut_with<'a>( &'a mut self, sink: &'a dyn Sink<Call = Self::Call>, ) -> TrackedMut<'a, Self>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".