1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::borrow;
use std::fmt;
use std::sync;
use liquid_compiler::Language;
use liquid_error::Error;
use liquid_error::Result;
use liquid_interpreter::PartialStore;
mod eager;
mod inmemory;
mod lazy;
mod ondemand;
pub use self::eager::*;
pub use self::inmemory::*;
pub use self::lazy::*;
pub use self::ondemand::*;
pub trait PartialCompiler {
fn compile(self, language: sync::Arc<Language>) -> Result<Box<PartialStore + Send + Sync>>;
}
pub trait PartialSource: fmt::Debug {
fn contains(&self, name: &str) -> bool;
fn names(&self) -> Vec<&str>;
fn try_get<'a>(&'a self, name: &str) -> Option<borrow::Cow<'a, str>>;
fn get<'a>(&'a self, name: &str) -> Result<borrow::Cow<'a, str>> {
self.try_get(name).ok_or_else(|| {
let mut available: Vec<_> = self.names();
available.sort_unstable();
let available = itertools::join(available, ", ");
Error::with_msg("Unknown partial-template")
.context("requested partial", name.to_owned())
.context("available partials", available)
})
}
}