From fdab7158c91c52a4ace211c804fdd8e9110f56de Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 19 Aug 2021 15:07:11 +0200 Subject: Pattern properties (#42) Included in this package are: * Code review I: The unnamed review. * Code Review II: How I met your review. * Code Review III: Code, the final frontier. These are the voyages of the USS Review ... --- src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 207567f8..d646cf6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,15 +49,15 @@ pub mod util; use std::rc::Rc; use crate::diag::TypResult; -use crate::eval::{Scope, State, Module}; -use crate::syntax::SyntaxTree; +use crate::eval::{Module, Scope, State}; use crate::font::FontStore; use crate::image::ImageStore; #[cfg(feature = "layout-cache")] -use crate::layout::LayoutCache; +use crate::layout::{EvictionStrategy, LayoutCache}; use crate::layout::{Frame, LayoutTree}; use crate::loading::Loader; use crate::source::{SourceId, SourceStore}; +use crate::syntax::SyntaxTree; /// The core context which holds the loader, configuration and cached artifacts. pub struct Context { @@ -141,6 +141,8 @@ impl Context { pub struct ContextBuilder { std: Option, state: Option, + #[cfg(feature = "layout-cache")] + policy: Option, } impl ContextBuilder { @@ -157,6 +159,13 @@ impl ContextBuilder { self } + /// The policy for eviction of the layout cache. + #[cfg(feature = "layout-cache")] + pub fn policy(mut self, policy: EvictionStrategy) -> Self { + self.policy = Some(policy); + self + } + /// Finish building the context by providing the `loader` used to load /// fonts, images, source files and other resources. pub fn build(self, loader: Rc) -> Context { @@ -166,7 +175,7 @@ impl ContextBuilder { images: ImageStore::new(Rc::clone(&loader)), loader, #[cfg(feature = "layout-cache")] - layouts: LayoutCache::new(), + layouts: LayoutCache::new(self.policy.unwrap_or_default()), std: self.std.unwrap_or(library::new()), state: self.state.unwrap_or_default(), } -- cgit v1.2.3