feat(tvix/castore/protos): return root node after validation

This allows avoiding a `.node.unwrap()`` after validation.

Change-Id: Ieef1ffebab16cdca94c979ca6831a7ab4f6007da
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11989
Reviewed-by: Brian Olsen <me@griff.name>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-07-20 16:34:32 +02:00 committed by flokli
parent c64c028366
commit 0244ae6eaf

View file

@ -116,9 +116,11 @@ impl NamedNode for node::Node {
impl Node {
/// Ensures the node has a valid enum kind (is Some), and passes its
// per-enum validation.
pub fn validate(&self) -> Result<(), ValidateNodeError> {
// The inner root node is returned for easier consumption.
pub fn validate(&self) -> Result<&node::Node, ValidateNodeError> {
if let Some(node) = self.node.as_ref() {
node.validate()
node.validate()?;
Ok(node)
} else {
Err(ValidateNodeError::NoNodeSet)
}