From 0153bdbf6c61cc6425b34803dcf86610093f7795 Mon Sep 17 00:00:00 2001 From: est31 Date: Wed, 12 May 2021 14:16:56 +0200 Subject: [PATCH] Replace rental with ouroboros rental is not maintained any more and users are encouraged to switch to alternatives. --- Cargo.toml | 2 +- src/imap_stream.rs | 6 +++--- src/lib.rs | 3 --- src/types/name.rs | 26 ++++++++++---------------- src/types/response_data.rs | 26 ++++++++++---------------- 5 files changed, 24 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aeda820..ce18696 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ async-native-tls = { version = "0.3.3" } async-std = { version = "1.8.0", default-features = false, features = ["std"] } pin-utils = "0.1.0-alpha.4" futures = "0.3.0" -rental = "0.5.5" +ouroboros = "0.9" stop-token = "0.2" byte-pool = "0.2.2" lazy_static = "1.4.0" diff --git a/src/imap_stream.rs b/src/imap_stream.rs index 6a5f55a..47a7927 100644 --- a/src/imap_stream.rs +++ b/src/imap_stream.rs @@ -108,7 +108,7 @@ impl ImapStream { let block: Block<'static> = self.buffer.take_block(); // Be aware, now self.buffer is invalid until block is returned or reset! - let res = ResponseData::try_new(block, |buf| { + let res = ResponseData::try_new_or_recover(block, |buf| { let buf = &buf[..self.buffer.used()]; log::trace!("decode: input: {:?}", std::str::from_utf8(buf)); match imap_proto::parser::parse_response(buf) { @@ -139,8 +139,8 @@ impl ImapStream { }); match res { Ok(response) => Ok(Some(response)), - Err(rental::RentalError(err, block)) => { - self.buffer.return_block(block); + Err((err, heads)) => { + self.buffer.return_block(heads.raw); match err { Some(err) => Err(err), None => Ok(None), diff --git a/src/lib.rs b/src/lib.rs index a92161b..91be90f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,9 +65,6 @@ #[macro_use] extern crate pin_utils; -#[macro_use] -extern crate rental; - // Reexport imap_proto for easier access. pub use imap_proto; diff --git a/src/types/name.rs b/src/types/name.rs index 42a0e53..efe9e0f 100644 --- a/src/types/name.rs +++ b/src/types/name.rs @@ -4,17 +4,13 @@ use imap_proto::{MailboxDatum, Response}; use crate::types::ResponseData; -rental! { - pub mod rents { - use super::*; - - /// A name that matches a `LIST` or `LSUB` command. - #[rental(debug, covariant)] - pub struct Name { - response: Box, - inner: InnerName<'response>, - } - } +/// A name that matches a `LIST` or `LSUB` command. +#[ouroboros::self_referencing(pub_extras)] +pub struct Name { + response: Box, + #[borrows(response)] + #[covariant] + inner: InnerName<'this>, } #[derive(PartialEq, Eq, Debug)] @@ -24,8 +20,6 @@ pub struct InnerName<'a> { name: &'a str, } -pub use rents::Name; - /// An attribute set for an IMAP name. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum NameAttribute<'a> { @@ -100,7 +94,7 @@ impl Name { /// Attributes of this name. pub fn attributes(&self) -> &[NameAttribute<'_>] { - &self.suffix().attributes[..] + &self.borrow_inner().attributes[..] } /// The hierarchy delimiter is a character used to delimit levels of hierarchy in a mailbox @@ -108,7 +102,7 @@ impl Name { /// of naming hierarchy. All children of a top-level hierarchy node use the same /// separator character. `None` means that no hierarchy exists; the name is a "flat" name. pub fn delimiter(&self) -> Option<&str> { - self.suffix().delimiter + self.borrow_inner().delimiter } /// The name represents an unambiguous left-to-right hierarchy, and are valid for use as a @@ -116,6 +110,6 @@ impl Name { /// the name is also valid as an argument for commands, such as `SELECT`, that accept mailbox /// names. pub fn name(&self) -> &str { - self.suffix().name + self.borrow_inner().name } } diff --git a/src/types/response_data.rs b/src/types/response_data.rs index 4a95a99..50049bc 100644 --- a/src/types/response_data.rs +++ b/src/types/response_data.rs @@ -3,20 +3,14 @@ use std::fmt; use byte_pool::Block; use imap_proto::{RequestId, Response}; -rental! { - pub mod rents { - use super::*; - - #[rental(covariant)] - pub struct ResponseData { - raw: Block<'static>, - response: Response<'raw>, - } - } +#[ouroboros::self_referencing(pub_extras)] +pub struct ResponseData { + raw: Block<'static>, + #[borrows(raw)] + #[covariant] + response: Response<'this>, } -pub use rents::ResponseData; - impl std::cmp::PartialEq for ResponseData { fn eq(&self, other: &Self) -> bool { self.parsed() == other.parsed() @@ -28,21 +22,21 @@ impl std::cmp::Eq for ResponseData {} impl fmt::Debug for ResponseData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ResponseData") - .field("raw", &self.head().len()) - .field("response", self.suffix()) + .field("raw", &self.borrow_raw().len()) + .field("response", self.borrow_response()) .finish() } } impl ResponseData { pub fn request_id(&self) -> Option<&RequestId> { - match self.suffix() { + match self.borrow_response() { Response::Done { ref tag, .. } => Some(tag), _ => None, } } pub fn parsed(&self) -> &Response<'_> { - self.suffix() + self.borrow_response() } }