From 3d3c77ecedf8fb797ab8b5b37dbd723174c317e5 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 17 Dec 2024 09:37:18 +0100 Subject: [PATCH] doc: StorePath.name() (cherry picked from commit 2f3dc27eb816634ebb8edbabd409ebc52db9a0bb) --- rust/nix-store/src/path.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rust/nix-store/src/path.rs b/rust/nix-store/src/path.rs index fc20382..a0cb301 100644 --- a/rust/nix-store/src/path.rs +++ b/rust/nix-store/src/path.rs @@ -11,6 +11,21 @@ pub struct StorePath { raw: NonNull, } impl StorePath { + /// Get the name of the store path. + /// + /// For a store path like `/nix/store/abc1234...-foo-1.2`, this function will return `foo-1.2`. + pub fn name(&self) -> Result { + unsafe { + let mut r = result_string_init!(); + raw::store_path_name( + self.as_ptr(), + Some(callback_get_result_string), + callback_get_result_string_data(&mut r), + ); + r + } + } + /// This is a low level function that you shouldn't have to call unless you are developing the Nix bindings. /// /// Construct a new `StorePath` by first cloning the C store path. @@ -37,17 +52,6 @@ impl StorePath { pub unsafe fn new_raw(raw: NonNull) -> Self { StorePath { raw } } - pub fn name(&self) -> Result { - unsafe { - let mut r = result_string_init!(); - raw::store_path_name( - self.as_ptr(), - Some(callback_get_result_string), - callback_get_result_string_data(&mut r), - ); - r - } - } /// This is a low level function that you shouldn't have to call unless you are developing the Nix bindings. ///