mirror of
https://github.com/typst/typst
synced 2025-05-20 20:15:29 +08:00
Implement World
for common pointer types of World
(#3838)
Co-authored-by: Ilia <43654815+istudyatuni@users.noreply.github.com>
This commit is contained in:
parent
8c28f67504
commit
8013f69714
@ -57,7 +57,7 @@ pub mod visualize;
|
||||
pub use typst_syntax as syntax;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::ops::Range;
|
||||
use std::ops::{Deref, Range};
|
||||
|
||||
use comemo::{Prehashed, Track, Tracked, Validate};
|
||||
use ecow::{EcoString, EcoVec};
|
||||
@ -231,6 +231,48 @@ pub trait World {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! delegate_for_ptr {
|
||||
($W:ident for $ptr:ty) => {
|
||||
impl<$W: World> World for $ptr {
|
||||
fn library(&self) -> &Prehashed<Library> {
|
||||
self.deref().library()
|
||||
}
|
||||
|
||||
fn book(&self) -> &Prehashed<FontBook> {
|
||||
self.deref().book()
|
||||
}
|
||||
|
||||
fn main(&self) -> Source {
|
||||
self.deref().main()
|
||||
}
|
||||
|
||||
fn source(&self, id: FileId) -> FileResult<Source> {
|
||||
self.deref().source(id)
|
||||
}
|
||||
|
||||
fn file(&self, id: FileId) -> FileResult<Bytes> {
|
||||
self.deref().file(id)
|
||||
}
|
||||
|
||||
fn font(&self, index: usize) -> Option<Font> {
|
||||
self.deref().font(index)
|
||||
}
|
||||
|
||||
fn today(&self, offset: Option<i64>) -> Option<Datetime> {
|
||||
self.deref().today(offset)
|
||||
}
|
||||
|
||||
fn packages(&self) -> &[(PackageSpec, Option<EcoString>)] {
|
||||
self.deref().packages()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
delegate_for_ptr!(W for std::boxed::Box<W>);
|
||||
delegate_for_ptr!(W for std::sync::Arc<W>);
|
||||
delegate_for_ptr!(W for &W);
|
||||
|
||||
/// Helper methods on [`World`] implementations.
|
||||
pub trait WorldExt {
|
||||
/// Get the byte range for a span.
|
||||
|
Loading…
x
Reference in New Issue
Block a user