about summary refs log tree commit diff
path: root/tvix/store/src/proto/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-12T17·46+0200
committerflokli <flokli@flokli.de>2023-10-12T20·46+0000
commit4da906bf34e8831ecabc835a84c31d1766ffb2c5 (patch)
tree92df2a7d2ed8445ffe01c74101214ddb0629196f /tvix/store/src/proto/mod.rs
parent3dd5ba042be0a36b0f94aba34414bb20a7e5ed61 (diff)
refactor(tvix/store/proto): merge two match statements into one r/6792
Change-Id: I3daca008dff5527169f5916f4845234e8f3263cd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9711
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: edef <edef@edef.eu>
Tested-by: BuildkiteCI
Diffstat (limited to '')
-rw-r--r--tvix/store/src/proto/mod.rs52
1 files changed, 23 insertions, 29 deletions
diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs
index 4bf4cfba1b..033fb79dbb 100644
--- a/tvix/store/src/proto/mod.rs
+++ b/tvix/store/src/proto/mod.rs
@@ -142,40 +142,34 @@ impl PathInfo {
 
         // Ensure there is a (root) node present, and it properly parses to a [StorePath].
         let root_nix_path = match &self.node {
-            None => {
-                return Err(ValidatePathInfoError::NoNodePresent());
+            None | Some(castorepb::Node { node: None }) => {
+                Err(ValidatePathInfoError::NoNodePresent())?
             }
-            Some(castorepb::Node { node }) => match node {
-                None => {
-                    return Err(ValidatePathInfoError::NoNodePresent());
-                }
-                Some(node) => {
-                    match node {
-                        // for a directory root node, ensure the digest has the appropriate size.
-                        castorepb::node::Node::Directory(directory_node) => {
-                            if TryInto::<B3Digest>::try_into(directory_node.digest.clone()).is_err()
-                            {
-                                return Err(ValidatePathInfoError::InvalidNodeDigestLen(
-                                    directory_node.digest.len(),
-                                ));
-                            }
+            Some(castorepb::Node { node: Some(node) }) => {
+                match node {
+                    // for a directory root node, ensure the digest has the appropriate size.
+                    castorepb::node::Node::Directory(directory_node) => {
+                        if TryInto::<B3Digest>::try_into(directory_node.digest.clone()).is_err() {
+                            return Err(ValidatePathInfoError::InvalidNodeDigestLen(
+                                directory_node.digest.len(),
+                            ));
                         }
-                        // for a file root node, ensure the digest has the appropriate size.
-                        castorepb::node::Node::File(file_node) => {
-                            // ensure the digest has the appropriate size.
-                            if TryInto::<B3Digest>::try_into(file_node.digest.clone()).is_err() {
-                                return Err(ValidatePathInfoError::InvalidNodeDigestLen(
-                                    file_node.digest.len(),
-                                ));
-                            }
+                    }
+                    // for a file root node, ensure the digest has the appropriate size.
+                    castorepb::node::Node::File(file_node) => {
+                        // ensure the digest has the appropriate size.
+                        if TryInto::<B3Digest>::try_into(file_node.digest.clone()).is_err() {
+                            return Err(ValidatePathInfoError::InvalidNodeDigestLen(
+                                file_node.digest.len(),
+                            ));
                         }
-                        // nothing to do specifically for symlinks
-                        castorepb::node::Node::Symlink(_) => {}
                     }
-                    // parse the name of the node itself and return
-                    parse_node_name_root(node.get_name(), ValidatePathInfoError::InvalidNodeName)?
+                    // nothing to do specifically for symlinks
+                    castorepb::node::Node::Symlink(_) => {}
                 }
-            },
+                // parse the name of the node itself and return
+                parse_node_name_root(node.get_name(), ValidatePathInfoError::InvalidNodeName)?
+            }
         };
 
         // return the root nix path