From d3eb94b69502261e212b0589ccda34bbcac5f4bc Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 19 Aug 2022 06:05:25 +0400 Subject: [PATCH] Fix `Clone` implementation for `ErasedRequester` --- CHANGELOG.md | 6 ++++++ src/adaptors/erased.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91b7e20b..cfe9d101 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +### Fixed + +- `ErasedRequester` now implements `Clone` even if `E` is not `Clone` ([#244][pr244]) + +[pr244]: https://github.com/teloxide/teloxide-core/pull/244 + ### Added - `From`, `From` and `From` impls for `RequestError` ([#241][pr241]) diff --git a/src/adaptors/erased.rs b/src/adaptors/erased.rs index 4dbae3a8..98dd2c95 100644 --- a/src/adaptors/erased.rs +++ b/src/adaptors/erased.rs @@ -10,7 +10,6 @@ use crate::{ }; /// [`Requester`] with erased type. -#[derive(Clone)] pub struct ErasedRequester<'a, E> { inner: Arc + 'a>, } @@ -37,6 +36,15 @@ impl std::fmt::Debug for ErasedRequester<'_, E> { } } +// NB. hand-written impl to avoid `E: Clone` bound +impl Clone for ErasedRequester<'_, E> { + fn clone(&self) -> Self { + Self { + inner: Arc::clone(&self.inner), + } + } +} + /// [`Request`] with erased type. #[must_use = "Requests are lazy and do nothing unless sent"] pub struct ErasedRequest<'a, T, E> {