From bc5db178c13d0837bd456488bed68b6adb8a559d Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 27 May 2024 22:12:07 +0000 Subject: [PATCH] feat: impl ContextInitializer for Option --- --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -116,6 +116,29 @@ } } +impl ContextInitializer for Option +where + T: ContextInitializer, +{ + fn initialize(&self, state: State, for_file: Source) -> Context { + if let Some(ctx) = self { + ctx.initialize(state, for_file) + } else { + ().initialize(state, for_file) + } + } + + fn populate(&self, for_file: Source, builder: &mut ContextBuilder) { + if let Some(ctx) = self { + ctx.populate(for_file, builder); + } + } + + fn as_any(&self) -> &dyn Any { + self + } +} + macro_rules! impl_context_initializer { ($($gen:ident)*) => { #[allow(non_snake_case)] -- gitstuff