Skip to content

Commit 2e8457e

Browse files
committed
Add some docs to FluentBundle::entry
1 parent ef71027 commit 2e8457e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

fluent-bundle/src/entry.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! `Entry` is used to store Messages, Terms and Functions in `FluentBundle` instances.
1+
//! `Entry` is used to store the lookup information for Messages, Terms and Functions in
2+
//! `FluentBundle` instances.
23
34
use std::borrow::Borrow;
45

@@ -12,24 +13,34 @@ use crate::types::FluentValue;
1213
pub type FluentFunction =
1314
Box<dyn for<'a> Fn(&[FluentValue<'a>], &FluentArgs) -> FluentValue<'a> + Send + Sync>;
1415

16+
type ResourceIdx = usize;
17+
type EntryIdx = usize;
18+
19+
/// The [`Entry`] stores indexes into the [`FluentBundle`]'s resources for Messages and Terms,
20+
/// and owns the [`Box`] pointers to the [`FluentFunction`].
1521
pub enum Entry {
16-
Message((usize, usize)),
17-
Term((usize, usize)),
22+
Message((ResourceIdx, EntryIdx)),
23+
Term((ResourceIdx, EntryIdx)),
1824
Function(FluentFunction),
1925
}
2026

2127
pub trait GetEntry {
28+
/// Looks up a message by its string ID, and returns it if it exists.
2229
fn get_entry_message(&self, id: &str) -> Option<&ast::Message<&str>>;
30+
31+
/// Looks up a term by its string ID, and returns it if it exists.
2332
fn get_entry_term(&self, id: &str) -> Option<&ast::Term<&str>>;
33+
34+
/// Looks up a function by its string ID, and returns it if it exists.
2435
fn get_entry_function(&self, id: &str) -> Option<&FluentFunction>;
2536
}
2637

2738
impl<'bundle, R: Borrow<FluentResource>, M> GetEntry for FluentBundle<R, M> {
2839
fn get_entry_message(&self, id: &str) -> Option<&ast::Message<&str>> {
2940
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)? {
41+
Entry::Message((resource_idx, entry_idx)) => {
42+
let res = self.resources.get(*resource_idx)?.borrow();
43+
if let ast::Entry::Message(ref msg) = res.get_entry(*entry_idx)? {
3344
Some(msg)
3445
} else {
3546
None
@@ -41,9 +52,9 @@ impl<'bundle, R: Borrow<FluentResource>, M> GetEntry for FluentBundle<R, M> {
4152

4253
fn get_entry_term(&self, id: &str) -> Option<&ast::Term<&str>> {
4354
self.entries.get(id).and_then(|ref entry| match entry {
44-
Entry::Term(pos) => {
45-
let res = self.resources.get(pos.0)?.borrow();
46-
if let ast::Entry::Term(ref msg) = res.get_entry(pos.1)? {
55+
Entry::Term((resource_idx, entry_idx)) => {
56+
let res = self.resources.get(*resource_idx)?.borrow();
57+
if let ast::Entry::Term(ref msg) = res.get_entry(*entry_idx)? {
4758
Some(msg)
4859
} else {
4960
None

0 commit comments

Comments
 (0)