tinymist_std::typst

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>

The standard library.

Can be created through Library::build().

fn book(&self) -> &LazyHash<FontBook>

Metadata about all known fonts.

fn main(&self) -> FileId

Get the file id of the main source file.

fn source(&self, id: FileId) -> Result<Source, FileError>

Try to access the specified source file.

fn file(&self, id: FileId) -> Result<Bytes, FileError>

Try to access the specified file.

fn font(&self, index: usize) -> Option<Font>

Try to access the font with the given index in the font book.

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.

Trait Implementations§

§

impl<'__comemo_dynamic> Track for dyn World + '__comemo_dynamic

§

fn track(&self) -> Tracked<'_, Self>

Start tracking all accesses to a value.
§

fn track_mut(&mut self) -> TrackedMut<'_, Self>

Start tracking all accesses and mutations to a value.
§

fn track_with<'a>( &'a self, constraint: &'a Self::Constraint, ) -> Tracked<'a, Self>

Start tracking all accesses into a constraint.
§

fn track_mut_with<'a>( &'a mut self, constraint: &'a Self::Constraint, ) -> TrackedMut<'a, Self>

Start tracking all accesses and mutations into a constraint.
§

impl<'__comemo_dynamic> Validate for dyn World + '__comemo_dynamic

§

type Constraint = ImmutableConstraint<__ComemoCall>

The constraints for this type.
§

fn validate( &self, constraint: &<dyn World + '__comemo_dynamic as Validate>::Constraint, ) -> bool

Whether this value fulfills the given constraints. Read more
§

fn validate_with_id( &self, constraint: &<dyn World + '__comemo_dynamic as Validate>::Constraint, id: usize, ) -> bool

Accelerated version of validate. Read more
§

fn replay( &mut self, constraint: &<dyn World + '__comemo_dynamic as Validate>::Constraint, )

Replay recorded mutations to the value.

Implementations on Foreign Types§

§

impl<W> World for &W
where W: World,

§

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>

§

impl<W> World for Box<W>
where W: World,

§

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>

§

impl<W> World for Arc<W>
where W: World,

§

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>

Implementors§