Merge pull request #189 from teloxide/with_payload

Add `HasPayload::with_payload_mut` function
This commit is contained in:
Waffle Maybe 2022-03-20 19:12:31 +04:00 committed by GitHub
commit 961e5aef9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -10,8 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `WrongFileIdOrUrl` and `FailedToGetUrlContent` errors ([#188][pr188])
- `HasPayload::with_payload_mut` function ([#189][pr189])
[pr188]: https://github.com/teloxide/teloxide-core/pull/188
[pr189]: https://github.com/teloxide/teloxide-core/pull/189
## 0.4.3 - 2022-03-08

View file

@ -28,6 +28,16 @@ pub trait HasPayload {
/// Gain immutable access to the underlying payload.
fn payload_ref(&self) -> &Self::Payload;
/// Update payload with a function
fn with_payload_mut<F>(mut self, f: F) -> Self
where
Self: Sized,
F: FnOnce(&mut Self::Payload),
{
f(self.payload_mut());
self
}
}
impl<P> HasPayload for P