From 488e7b849202cc4df93d11f6b2e82a298b993eaa Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 22 Jul 2022 17:57:51 +1000 Subject: [PATCH] Update `CratesToml::append` to accept iter intead of one single pair of value. Signed-off-by: Jiahao XU --- src/metafiles/v1.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/metafiles/v1.rs b/src/metafiles/v1.rs index 3b98568d..e356ec60 100644 --- a/src/metafiles/v1.rs +++ b/src/metafiles/v1.rs @@ -1,6 +1,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, fs, io, + iter::IntoIterator, path::{Path, PathBuf}, str::FromStr, }; @@ -44,11 +45,13 @@ impl CratesToml { Ok(()) } - pub fn append_to_path( + pub fn append_to_path<'a, Iter>( path: impl AsRef, - cvs: &CrateVersionSource, - bins: BTreeSet, - ) -> Result<(), CratesTomlParseError> { + iter: Iter, + ) -> Result<(), CratesTomlParseError> + where + Iter: IntoIterator)>, + { let mut c1 = match Self::load_from_path(path.as_ref()) { Ok(c1) => c1, Err(CratesTomlParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => { @@ -56,17 +59,19 @@ impl CratesToml { } Err(err) => return Err(err), }; - c1.insert(cvs, bins); + for (cvs, bins) in iter { + c1.insert(cvs, bins); + } c1.write_to_path(path.as_ref())?; Ok(()) } - pub fn append( - cvs: &CrateVersionSource, - bins: BTreeSet, - ) -> Result<(), CratesTomlParseError> { - Self::append_to_path(Self::default_path()?, cvs, bins) + pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError> + where + Iter: IntoIterator)>, + { + Self::append_to_path(Self::default_path()?, iter) } }