Skip to content

Commit 6572bdf

Browse files
est31link2xt
authored andcommitted
Replace rental with ouroboros
rental is not maintained any more and users are encouraged to switch to alternatives.
1 parent 4ce7da4 commit 6572bdf

File tree

7 files changed

+25
-41
lines changed

7 files changed

+25
-41
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async-native-tls = { version = "0.3.3" }
3030
async-std = { version = "1.8.0", default-features = false, features = ["std"] }
3131
pin-utils = "0.1.0-alpha.4"
3232
futures = "0.3.15"
33-
rental = "0.5.5"
33+
ouroboros = "0.9"
3434
stop-token = "0.2"
3535
byte-pool = "0.2.2"
3636
lazy_static = "1.4.0"

examples/idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn fetch_and_idle(imap_server: &str, login: &str, password: &str) -> Resul
7373
println!("-- IDLE timed out");
7474
}
7575
NewData(data) => {
76-
let s = String::from_utf8(data.head().to_vec()).unwrap();
76+
let s = String::from_utf8(data.borrow_raw().to_vec()).unwrap();
7777
println!("-- IDLE data:\n{}", s);
7878
}
7979
}

src/imap_stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
108108
let block: Block<'static> = self.buffer.take_block();
109109
// Be aware, now self.buffer is invalid until block is returned or reset!
110110

111-
let res = ResponseData::try_new(block, |buf| {
111+
let res = ResponseData::try_new_or_recover(block, |buf| {
112112
let buf = &buf[..self.buffer.used()];
113113
log::trace!("decode: input: {:?}", std::str::from_utf8(buf));
114114
match imap_proto::parser::parse_response(buf) {
@@ -139,8 +139,8 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
139139
});
140140
match res {
141141
Ok(response) => Ok(Some(response)),
142-
Err(rental::RentalError(err, block)) => {
143-
self.buffer.return_block(block);
142+
Err((err, heads)) => {
143+
self.buffer.return_block(heads.raw);
144144
match err {
145145
Some(err) => Err(err),
146146
None => Ok(None),

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
#[macro_use]
6666
extern crate pin_utils;
6767

68-
#[macro_use]
69-
extern crate rental;
70-
7168
// Reexport imap_proto for easier access.
7269
pub use imap_proto;
7370

src/parse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ mod tests {
342342
assert_eq!(remaining.len(), 0);
343343
Ok(response)
344344
})
345-
.map_err(|err: rental::RentalError<io::Error, _>| err.0)
346345
})
347346
.collect()
348347
}

src/types/name.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ use imap_proto::{MailboxDatum, Response};
44

55
use crate::types::ResponseData;
66

7-
rental! {
8-
pub mod rents {
9-
use super::*;
10-
11-
/// A name that matches a `LIST` or `LSUB` command.
12-
#[rental(debug, covariant)]
13-
pub struct Name {
14-
response: Box<ResponseData>,
15-
inner: InnerName<'response>,
16-
}
17-
}
7+
/// A name that matches a `LIST` or `LSUB` command.
8+
#[ouroboros::self_referencing(pub_extras)]
9+
pub struct Name {
10+
response: Box<ResponseData>,
11+
#[borrows(response)]
12+
#[covariant]
13+
inner: InnerName<'this>,
1814
}
1915

2016
#[derive(PartialEq, Eq, Debug)]
@@ -24,8 +20,6 @@ pub struct InnerName<'a> {
2420
name: &'a str,
2521
}
2622

27-
pub use rents::Name;
28-
2923
/// An attribute set for an IMAP name.
3024
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3125
pub enum NameAttribute<'a> {
@@ -103,22 +97,22 @@ impl Name {
10397

10498
/// Attributes of this name.
10599
pub fn attributes(&self) -> &[NameAttribute<'_>] {
106-
&self.suffix().attributes[..]
100+
&self.borrow_inner().attributes[..]
107101
}
108102

109103
/// The hierarchy delimiter is a character used to delimit levels of hierarchy in a mailbox
110104
/// name. A client can use it to create child mailboxes, and to search higher or lower levels
111105
/// of naming hierarchy. All children of a top-level hierarchy node use the same
112106
/// separator character. `None` means that no hierarchy exists; the name is a "flat" name.
113107
pub fn delimiter(&self) -> Option<&str> {
114-
self.suffix().delimiter
108+
self.borrow_inner().delimiter
115109
}
116110

117111
/// The name represents an unambiguous left-to-right hierarchy, and are valid for use as a
118112
/// reference in `LIST` and `LSUB` commands. Unless [`NameAttribute::NoSelect`] is indicated,
119113
/// the name is also valid as an argument for commands, such as `SELECT`, that accept mailbox
120114
/// names.
121115
pub fn name(&self) -> &str {
122-
self.suffix().name
116+
self.borrow_inner().name
123117
}
124118
}

src/types/response_data.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ use std::fmt;
33
use byte_pool::Block;
44
use imap_proto::{RequestId, Response};
55

6-
rental! {
7-
pub mod rents {
8-
use super::*;
9-
10-
#[rental(covariant)]
11-
pub struct ResponseData {
12-
raw: Block<'static>,
13-
response: Response<'raw>,
14-
}
15-
}
6+
#[ouroboros::self_referencing(pub_extras)]
7+
pub struct ResponseData {
8+
pub raw: Block<'static>,
9+
#[borrows(raw)]
10+
#[covariant]
11+
response: Response<'this>,
1612
}
1713

18-
pub use rents::ResponseData;
19-
2014
impl std::cmp::PartialEq for ResponseData {
2115
fn eq(&self, other: &Self) -> bool {
2216
self.parsed() == other.parsed()
@@ -28,21 +22,21 @@ impl std::cmp::Eq for ResponseData {}
2822
impl fmt::Debug for ResponseData {
2923
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3024
f.debug_struct("ResponseData")
31-
.field("raw", &self.head().len())
32-
.field("response", self.suffix())
25+
.field("raw", &self.borrow_raw().len())
26+
.field("response", self.borrow_response())
3327
.finish()
3428
}
3529
}
3630

3731
impl ResponseData {
3832
pub fn request_id(&self) -> Option<&RequestId> {
39-
match self.suffix() {
33+
match self.borrow_response() {
4034
Response::Done { ref tag, .. } => Some(tag),
4135
_ => None,
4236
}
4337
}
4438

4539
pub fn parsed(&self) -> &Response<'_> {
46-
self.suffix()
40+
self.borrow_response()
4741
}
4842
}

0 commit comments

Comments
 (0)