1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 15:51:06 +01:00

Update Session::set_session to take IntoIterator (#105)

This commit is contained in:
FallenWarrior2k 2020-09-22 01:04:21 +02:00 committed by GitHub
parent 03ccf09e2e
commit bb8120a8c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -156,7 +156,7 @@ where
Box::pin(async move {
let state = inner.load(&req).await?;
let value = if let Some((state, value)) = state {
Session::set_session(state.into_iter(), &mut req);
Session::set_session(state, &mut req);
Some(value)
} else {
None

View File

@ -1,6 +1,7 @@
# Changes
## Unreleased - 2020-xx-xx
* `Session::set_session` takes a `IntoIterator` instead of `Iterator`
## 0.4.0 - 2020-09-11

View File

@ -356,7 +356,7 @@ where
let inner = self.inner.clone();
let (is_new, state) = self.inner.load(&req);
let prolong_expiration = self.inner.expires_in.is_some();
Session::set_session(state.into_iter(), &mut req);
Session::set_session(state, &mut req);
let fut = self.service.call(req);

View File

@ -197,12 +197,12 @@ impl Session {
/// let mut req = test::TestRequest::default().to_srv_request();
///
/// Session::set_session(
/// vec![("counter".to_string(), serde_json::to_string(&0).unwrap())].into_iter(),
/// vec![("counter".to_string(), serde_json::to_string(&0).unwrap())],
/// &mut req,
/// );
/// ```
pub fn set_session(
data: impl Iterator<Item = (String, String)>,
data: impl IntoIterator<Item = (String, String)>,
req: &mut ServiceRequest,
) {
let session = Session::get_session(&mut *req.extensions_mut());
@ -279,8 +279,7 @@ mod tests {
let mut req = test::TestRequest::default().to_srv_request();
Session::set_session(
vec![("key".to_string(), serde_json::to_string("value").unwrap())]
.into_iter(),
vec![("key".to_string(), serde_json::to_string("value").unwrap())],
&mut req,
);
let session = Session::get_session(&mut *req.extensions_mut());
@ -301,7 +300,7 @@ mod tests {
let mut req = test::TestRequest::default().to_srv_request();
Session::set_session(
vec![("key".to_string(), serde_json::to_string(&true).unwrap())].into_iter(),
vec![("key".to_string(), serde_json::to_string(&true).unwrap())],
&mut req,
);
@ -315,7 +314,7 @@ mod tests {
let mut req = test::TestRequest::default().to_srv_request();
Session::set_session(
vec![("key".to_string(), serde_json::to_string(&10).unwrap())].into_iter(),
vec![("key".to_string(), serde_json::to_string(&10).unwrap())],
&mut req,
);