# HG changeset patch # User Arseniy Alekseyev # Date 2021-10-19 09:52:13 # Node ID e9faae0f445c9f22757a3ded3265c4c273c33d5c # Parent 7f23a472068f3248a13870f50ad5234d5ad7b126 rhg: simplify split_metadata It turns out that it's possible to implement `FilelogEntry.into_data` on top of `split`, as proposed by @spectral. Differential Revision: https://phab.mercurial-scm.org/D11689 diff --git a/rust/hg-core/src/revlog/filelog.rs b/rust/hg-core/src/revlog/filelog.rs --- a/rust/hg-core/src/revlog/filelog.rs +++ b/rust/hg-core/src/revlog/filelog.rs @@ -54,28 +54,18 @@ pub struct FilelogEntry(Vec); impl FilelogEntry { /// Split into metadata and data - /// Returns None if there is no metadata, so the entire entry is data. - fn split_metadata(&self) -> Result, HgError> { + pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { const DELIMITER: &[u8; 2] = &[b'\x01', b'\n']; if let Some(rest) = self.0.drop_prefix(DELIMITER) { if let Some((metadata, data)) = rest.split_2_by_slice(DELIMITER) { - Ok(Some((metadata, data))) + Ok((Some(metadata), data)) } else { Err(HgError::corrupted( "Missing metadata end delimiter in filelog entry", )) } } else { - Ok(None) - } - } - - /// Split into metadata and data - pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { - if let Some((metadata, data)) = self.split_metadata()? { - Ok((Some(metadata), data)) - } else { Ok((None, &self.0)) } } @@ -89,7 +79,7 @@ impl FilelogEntry { /// Consume the entry, and convert it into data, discarding any metadata, /// if present. pub fn into_data(self) -> Result, HgError> { - if let Some((_metadata, data)) = self.split_metadata()? { + if let (Some(_metadata), data) = self.split()? { Ok(data.to_owned()) } else { Ok(self.0)