From d38cf51c63061cfe44d67bd1bf93694c8a89b41e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 10 Apr 2024 14:24:01 +0200 Subject: [PATCH] feat: Context.is_key_error (cherry picked from commit f754e243852103164dbc6fdaf8c0cccb3c85cfb1) --- rust/nix-util/src/context.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rust/nix-util/src/context.rs b/rust/nix-util/src/context.rs index 772511e..73540ca 100644 --- a/rust/nix-util/src/context.rs +++ b/rust/nix-util/src/context.rs @@ -34,6 +34,10 @@ impl Context { } Ok(()) } + /// NIX_ERR_KEY is returned when e.g. an attribute is missing. Return true if the error is of this type. + pub fn is_key_error(&self) -> bool { + unsafe { raw::err_code(self.inner.as_ptr()) == raw::NIX_ERR_KEY } + } } impl Drop for Context {