mononoke/manifest: add Entry::map_leaf and Entry::map_tree

Summary: It's useful sometimes, like in the next diff.

Reviewed By: mitrandir77

Differential Revision: D25422597

fbshipit-source-id: 0ebb5dcc349bbaacac3dddf03f19e5e092042468
This commit is contained in:
Thomas Orozco 2020-12-10 03:06:10 -08:00 committed by Facebook GitHub Bot
parent 0578e28081
commit c9568598fb

View File

@ -126,6 +126,20 @@ impl<T, L> Entry<T, L> {
_ => None,
}
}
pub fn map_leaf<L2>(self, m: impl FnOnce(L) -> L2) -> Entry<T, L2> {
match self {
Entry::Tree(tree) => Entry::Tree(tree),
Entry::Leaf(leaf) => Entry::Leaf(m(leaf)),
}
}
pub fn map_tree<T2>(self, m: impl FnOnce(T) -> T2) -> Entry<T2, L> {
match self {
Entry::Tree(tree) => Entry::Tree(m(tree)),
Entry::Leaf(leaf) => Entry::Leaf(leaf),
}
}
}
#[async_trait]