| Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame^] | 1 | #[cfg(feature = "bytes")] |
| 2 | use bytes::Bytes; |
| 3 | |
| 4 | /// anything that can be cleared |
| 5 | pub trait Clear { |
| 6 | /// Clear this make, make it equivalent to newly created object. |
| 7 | fn clear(&mut self); |
| 8 | } |
| 9 | |
| 10 | impl<T> Clear for Option<T> { |
| 11 | fn clear(&mut self) { |
| 12 | self.take(); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | impl Clear for String { |
| 17 | fn clear(&mut self) { |
| 18 | String::clear(self); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl<T> Clear for Vec<T> { |
| 23 | fn clear(&mut self) { |
| 24 | Vec::clear(self); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | #[cfg(feature = "bytes")] |
| 29 | impl Clear for Bytes { |
| 30 | fn clear(&mut self) { |
| 31 | Bytes::clear(self); |
| 32 | } |
| 33 | } |