summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authortingerrr <me@tinger.dev>2024-04-04 11:37:23 +0200
committerGitHub <noreply@github.com>2024-04-04 09:37:23 +0000
commit8013f69714456043f5334670b6ecec2963309622 (patch)
tree3d11d0601fa969287001c5ec2bbe172d4f464837 /crates
parent8c28f67504256998584d89bab7e3805599f72e00 (diff)
Implement `World` for common pointer types of `World` (#3838)
Co-authored-by: Ilia <43654815+istudyatuni@users.noreply.github.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/lib.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/crates/typst/src/lib.rs b/crates/typst/src/lib.rs
index 3b09cb49..35915e2b 100644
--- a/crates/typst/src/lib.rs
+++ b/crates/typst/src/lib.rs
@@ -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.