1 //! `Entry` is used to store Messages, Terms and Functions in `FluentBundle` instances.
3 use std::borrow::Borrow;
5 use fluent_syntax::ast;
7 use crate::args::FluentArgs;
8 use crate::bundle::FluentBundle;
9 use crate::resource::FluentResource;
10 use crate::types::FluentValue;
12 pub type FluentFunction =
13 Box<dyn for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Send + Sync>;
16 Message((usize, usize)),
18 Function(FluentFunction),
22 fn get_entry_message(&self, id: &str) -> Option<&ast::Message<&str>>;
23 fn get_entry_term(&self, id: &str) -> Option<&ast::Term<&str>>;
24 fn get_entry_function(&self, id: &str) -> Option<&FluentFunction>;
27 impl<'bundle, R: Borrow<FluentResource>, M> GetEntry for FluentBundle<R, M> {
28 fn get_entry_message(&self, id: &str) -> Option<&ast::Message<&str>> {
29 self.entries.get(id).and_then(|ref entry| match entry {
30 Entry::Message(pos) => {
31 let res = self.resources.get(pos.0)?.borrow();
32 if let ast::Entry::Message(ref msg) = res.get_entry(pos.1)? {
42 fn get_entry_term(&self, id: &str) -> Option<&ast::Term<&str>> {
43 self.entries.get(id).and_then(|ref entry| match entry {
45 let res = self.resources.get(pos.0)?.borrow();
46 if let ast::Entry::Term(ref msg) = res.get_entry(pos.1)? {
56 fn get_entry_function(&self, id: &str) -> Option<&FluentFunction> {
57 self.entries.get(id).and_then(|ref entry| match entry {
58 Entry::Function(function) => Some(function),