From f22232533937b157a926af9840777a38e4a21883 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 1 May 2024 13:23:15 +0000 Subject: fix(tvix/castore/path): join, push -> try_{join,push} These are fallible methods, so they should be named accordingly. Change-Id: I6dc271c42989dd6500173488190f65381835d6fe Reviewed-on: https://cl.tvl.fyi/c/depot/+/11572 Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/castore/src/path.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tvix/castore/src/path.rs b/tvix/castore/src/path.rs index 34fac5a2f8c0..498f9a91b06a 100644 --- a/tvix/castore/src/path.rs +++ b/tvix/castore/src/path.rs @@ -73,10 +73,10 @@ impl Path { } /// Creates a PathBuf with `name` adjoined to self. - pub fn join(&self, name: &[u8]) -> Result { + pub fn try_join(&self, name: &[u8]) -> Result { let mut v = PathBuf::with_capacity(self.inner.len() + name.len() + 1); v.inner.extend_from_slice(&self.inner); - v.push(name)?; + v.try_push(name)?; Ok(v) } @@ -204,7 +204,7 @@ impl PathBuf { } /// Adjoins `name` to self. - pub fn push(&mut self, name: &[u8]) -> Result<(), std::io::Error> { + pub fn try_push(&mut self, name: &[u8]) -> Result<(), std::io::Error> { validate_node_name(name).map_err(|_| std::io::ErrorKind::InvalidData)?; if !self.inner.is_empty() { @@ -299,8 +299,8 @@ mod test { #[case("a", "b", "a/b")] #[case("a", "b", "a/b")] pub fn join_push(#[case] mut p: PathBuf, #[case] name: &str, #[case] exp_p: PathBuf) { - assert_eq!(exp_p, p.join(name.as_bytes()).expect("join failed")); - p.push(name.as_bytes()).expect("push failed"); + assert_eq!(exp_p, p.try_join(name.as_bytes()).expect("join failed")); + p.try_push(name.as_bytes()).expect("push failed"); assert_eq!(exp_p, p); } @@ -314,9 +314,9 @@ mod test { #[case("", ".")] #[case("", "..")] pub fn join_push_fail(#[case] mut p: PathBuf, #[case] name: &str) { - p.join(name.as_bytes()) + p.try_join(name.as_bytes()) .expect_err("join succeeded unexpectedly"); - p.push(name.as_bytes()) + p.try_push(name.as_bytes()) .expect_err("push succeeded unexpectedly"); } -- cgit 1.4.1