Skip to content

Commit

Permalink
Remove clone calls for Options
Browse files Browse the repository at this point in the history
  • Loading branch information
gngeorgiev committed Nov 21, 2021
1 parent 391cc5e commit fee5f45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/compare_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn clean(version: &str, opts: Option<Options>) -> Result<String, Error> {

/// Compares the ordering of [Version](crate::Version) `a` vs [Version](crate::Version) `b`.
pub fn compare(a: &str, b: &str, opts: Option<Options>) -> Result<Ordering, Error> {
let a = parse(a, opts.clone())?;
let a = parse(a, opts)?;
let b = parse(b, opts)?;
Ok(a.partial_cmp(&b).unwrap())
}
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn cmp(a: &str, op: Operator, b: &str, opts: Option<Options>) -> Result<bool

/// Checks whether [Version](crate::Version) is in a [Range](crate::range).
pub fn satisfies(ver: &str, range: &str, opts: Option<Options>) -> Result<bool, Error> {
let range = Range::new(range).with_options_maybe(opts.clone()).parse()?;
let range = Range::new(range).with_options_maybe(opts).parse()?;
let ver = Version::new(ver).with_options_maybe(opts).parse()?;
Ok(range.test(&ver))
}
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ mod tests {
for (v1, v2, loose) in v {
println!("testing compares: {} {} loose: {}", v1, v2, loose);
let opts = Options::builder().loose(loose).build();
let res = super::compare(v1, v2, Some(opts.clone())).unwrap();
let res = super::compare(v1, v2, Some(opts)).unwrap();
assert!(res == Ordering::Greater);
assert!(super::compare(v1, v1, Some(opts.clone())).unwrap() == Ordering::Equal);
assert!(super::compare(v2, v2, Some(opts.clone())).unwrap() == Ordering::Equal);
assert!(super::compare(v1, v1, Some(opts)).unwrap() == Ordering::Equal);
assert!(super::compare(v2, v2, Some(opts)).unwrap() == Ordering::Equal);
}
}

Expand Down Expand Up @@ -195,10 +195,10 @@ mod tests {
for (v1, v2, loose) in v {
println!("testing equality: {} {} loose: {}", v1, v2, loose);
let opts = Options::builder().loose(loose).build();
let res = super::compare(v1, v2, Some(opts.clone())).unwrap();
let res = super::compare(v1, v2, Some(opts)).unwrap();
assert!(res == Ordering::Equal);
assert!(super::cmp(v1, Operator::Gte, v2, Some(opts.clone())).unwrap());
assert!(super::cmp(v1, Operator::Lte, v2, Some(opts.clone())).unwrap());
assert!(super::cmp(v1, Operator::Gte, v2, Some(opts)).unwrap());
assert!(super::cmp(v1, Operator::Lte, v2, Some(opts)).unwrap());
}
}

Expand Down Expand Up @@ -312,7 +312,7 @@ mod tests {
for (range, ver, loose) in v {
println!("testing satisfies: {} {} loose: {}", range, ver, loose);
let opts = Options::builder().loose(loose).build();
let res = super::satisfies(ver, range, Some(opts.clone())).unwrap();
let res = super::satisfies(ver, range, Some(opts)).unwrap();
assert!(res);
}
}
Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
range, ver, loose
);
let opts = Options::builder().loose(loose).build();
let res = super::satisfies(ver, range, Some(opts.clone())).unwrap_or(false);
let res = super::satisfies(ver, range, Some(opts)).unwrap_or(false);
assert!(!res);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Range {

impl<'p> Parseable<'p> for Range {
fn parse(range_input: &'p str, opts: Option<Options>) -> Result<Self, Error> {
let loose = opts.clone().unwrap_or_default().loose;
let loose = opts.unwrap_or_default().loose;

if range_input.is_empty() {
let comp = Comparator::empty();
Expand All @@ -56,7 +56,7 @@ impl<'p> Parseable<'p> for Range {
});
}

let comparators_opts = opts.clone();
let comparators_opts = opts;
let comparators_result: Result<Vec<Option<Vec<Comparator>>>, Error> = RANGE_OR
.split(range_input)
.map(move |range: &str| {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'p> Parseable<'p> for Range {
// when used on an empty string, just like in the original npm package.
// The condition above is a workaround atm

let opts = comparators_opts.clone();
let opts = comparators_opts;
let comparators = SPLIT_SPACES
.split(&comparators_parsed)
.filter(|c| {
Expand All @@ -109,7 +109,7 @@ impl<'p> Parseable<'p> for Range {
true
}
})
.map(move |r| Comparator::new(r.to_owned(), opts.clone()))
.map(move |r| Comparator::new(r.to_owned(), opts))
.collect::<Result<Vec<_>, Error>>();

match comparators {
Expand Down

0 comments on commit fee5f45

Please sign in to comment.