1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

pass request ownership to closure instead of ref

This commit is contained in:
Nikolay Kim 2019-04-16 15:43:55 -07:00
parent 5740f1e63a
commit cc8420377e
2 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,12 @@
# Changes # Changes
## [0.1.1] - 2019-04-xx
### Changed
* `ClientRequest::if_true()` and `ClientRequest::if_some()` use instance instead of ref
## [0.1.0] - 2019-04-16 ## [0.1.0] - 2019-04-16
* No changes * No changes

View File

@ -333,24 +333,26 @@ impl ClientRequest {
/// value is `true`. /// value is `true`.
pub fn if_true<F>(mut self, value: bool, f: F) -> Self pub fn if_true<F>(mut self, value: bool, f: F) -> Self
where where
F: FnOnce(&mut ClientRequest), F: FnOnce(ClientRequest) -> ClientRequest,
{ {
if value { if value {
f(&mut self); f(self)
} else {
self
} }
self
} }
/// This method calls provided closure with builder reference if /// This method calls provided closure with builder reference if
/// value is `Some`. /// value is `Some`.
pub fn if_some<T, F>(mut self, value: Option<T>, f: F) -> Self pub fn if_some<T, F>(mut self, value: Option<T>, f: F) -> Self
where where
F: FnOnce(T, &mut ClientRequest), F: FnOnce(T, ClientRequest) -> ClientRequest,
{ {
if let Some(val) = value { if let Some(val) = value {
f(val, &mut self); f(val, self)
} else {
self
} }
self
} }
/// Complete request construction and send body. /// Complete request construction and send body.