From c9568598fbe71dabe764352f1ff7b9d91919387e Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Thu, 10 Dec 2020 03:06:10 -0800 Subject: [PATCH] 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 --- eden/mononoke/manifest/src/types.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/eden/mononoke/manifest/src/types.rs b/eden/mononoke/manifest/src/types.rs index dde591dd17..372d2120b7 100644 --- a/eden/mononoke/manifest/src/types.rs +++ b/eden/mononoke/manifest/src/types.rs @@ -126,6 +126,20 @@ impl Entry { _ => None, } } + + pub fn map_leaf(self, m: impl FnOnce(L) -> L2) -> Entry { + match self { + Entry::Tree(tree) => Entry::Tree(tree), + Entry::Leaf(leaf) => Entry::Leaf(m(leaf)), + } + } + + pub fn map_tree(self, m: impl FnOnce(T) -> T2) -> Entry { + match self { + Entry::Tree(tree) => Entry::Tree(m(tree)), + Entry::Leaf(leaf) => Entry::Leaf(leaf), + } + } } #[async_trait]