tytanic_core/world_builder/
library.rs1use typst::Library;
2use typst::LibraryBuilder;
3use typst::LibraryExt;
4use typst::utils::LazyHash;
5
6use super::ProvideLibrary;
7
8#[derive(Debug)]
10pub struct LibraryProvider {
11 library: LazyHash<Library>,
12}
13
14impl LibraryProvider {
15 pub fn new() -> Self {
17 Self::with_library(Library::default())
18 }
19
20 pub fn with_library(library: Library) -> Self {
22 Self {
23 library: LazyHash::new(library),
24 }
25 }
26
27 pub fn with_builder(f: impl FnOnce(&mut LibraryBuilder) -> &mut LibraryBuilder) -> Self {
29 let mut builder = Library::builder();
30 f(&mut builder);
31 Self::with_library(builder.build())
32 }
33}
34
35impl LibraryProvider {
36 pub fn library(&self) -> &LazyHash<Library> {
38 &self.library
39 }
40}
41
42impl Default for LibraryProvider {
43 fn default() -> Self {
44 Self::new()
45 }
46}
47
48impl ProvideLibrary for LibraryProvider {
49 fn provide_library(&self) -> &LazyHash<Library> {
50 self.library()
51 }
52}