From 7f7c1ae7be97a54e8a52bda29e6d2c22f2efb822 Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 27 Oct 2023 11:35:09 +0000 Subject: refactor(nix-compat/store_path): make digest and name private Change-Id: I62cbe883afcf3dd0c8d4de0e3b845069eb750c97 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9855 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/mod.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tvix/nix-compat/src/store_path') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index c1df442adc89..93b1d80bbfe3 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -52,8 +52,18 @@ pub enum Error { /// path. #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct StorePath { - pub digest: [u8; DIGEST_SIZE], - pub name: String, + digest: [u8; DIGEST_SIZE], + name: String, +} + +impl StorePath { + pub fn digest(&self) -> &[u8; DIGEST_SIZE] { + &self.digest + } + + pub fn name(&self) -> &str { + self.name.as_ref() + } } impl PartialOrd for StorePath { @@ -187,14 +197,6 @@ pub(crate) fn validate_name(s: &[u8]) -> Result { Ok(String::from_utf8(s.to_vec()).unwrap()) } -/// Ensures the StorePath fulfils the requirements for store paths. -/// Useful when populating the struct manually instead of parsing. -pub fn validate(s: &StorePath) -> Result<(), Error> { - validate_name(s.name.as_bytes())?; - - Ok(()) -} - impl fmt::Display for StorePath { /// The string representation of a store path starts with a digest (20 /// bytes), [crate::nixbase32]-encoded, followed by a `-`, -- cgit 1.4.1