Refactor: Use mut-ref to insert instead move of cookies value

This commit is contained in:
winkidney 2019-01-01 00:49:41 -08:00
parent 8bd8ee7b18
commit 5eb4ee27e8
1 changed files with 7 additions and 9 deletions

View File

@ -550,21 +550,19 @@ impl<S: 'static> TestRequest<S> {
/// set cookie of this request /// set cookie of this request
pub fn cookie(mut self, cookie: Cookie<'static>) -> Self { pub fn cookie(mut self, cookie: Cookie<'static>) -> Self {
let mut should_insert = true; let mut should_insert = true;
let mut cookies = match self.cookies { match &mut self.cookies {
Some(old_cookies) => { Some(old_cookies) => {
for old_cookie in &old_cookies { for old_cookie in old_cookies.iter() {
if old_cookie == &cookie { if old_cookie == &cookie {
should_insert = false should_insert = false
}; };
}
old_cookies
}
None => { Vec::<Cookie>::new() }
}; };
if should_insert { if should_insert {
cookies.push(cookie) old_cookies.push(cookie);
};
}
None => {}
}; };
self.cookies = Some(cookies);
self self
} }