Skip to content

Commit

Permalink
fix: switch from ouroboros to self_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Jun 13, 2023
1 parent f34d352 commit 6949401
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ base64 = "0.21"
chrono = { version = "0.4", default-features = false, features = ["std"] }
pin-utils = "0.1.0-alpha.4"
futures = "0.3.15"
ouroboros = "0.15"
self_cell = "1.0.1"
stop-token = "0.7"
byte-pool = "0.2.4"
once_cell = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn fetch_and_idle(imap_server: &str, login: &str, password: &str) -> Resul
println!("-- IDLE timed out");
}
NewData(data) => {
let s = String::from_utf8(data.borrow_raw().to_vec()).unwrap();
let s = String::from_utf8(data.borrow_owner().to_vec()).unwrap();
println!("-- IDLE data:\n{}", s);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/imap_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
});
match res {
Ok(response) => Ok(Some(response)),
Err((err, heads)) => {
self.buffer.return_block(heads.raw);
Err((heads, err)) => {
self.buffer.return_block(heads);
match err {
Some(err) => Err(err),
None => Ok(None),
Expand Down
27 changes: 15 additions & 12 deletions src/types/name.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
pub use imap_proto::types::NameAttribute;
use imap_proto::{MailboxDatum, Response};
use self_cell::self_cell;

use crate::types::ResponseData;

/// A name that matches a `LIST` or `LSUB` command.
#[ouroboros::self_referencing(pub_extras)]
#[derive(Debug)]
pub struct Name {
response: Box<ResponseData>,
#[borrows(response)]
#[covariant]
inner: InnerName<'this>,
}
self_cell!(
/// A name that matches a `LIST` or `LSUB` command.
pub struct Name {
owner: Box<ResponseData>,

#[covariant]
dependent: InnerName,
}

impl { Debug }
);

#[derive(PartialEq, Eq, Debug)]
pub struct InnerName<'a> {
Expand All @@ -38,22 +41,22 @@ impl Name {

/// Attributes of this name.
pub fn attributes(&self) -> &[NameAttribute<'_>] {
&self.borrow_inner().attributes[..]
&self.borrow_dependent().attributes[..]
}

/// The hierarchy delimiter is a character used to delimit levels of hierarchy in a mailbox
/// name. A client can use it to create child mailboxes, and to search higher or lower levels
/// 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.borrow_inner().delimiter
self.borrow_dependent().delimiter
}

/// The name represents an unambiguous left-to-right hierarchy, and are valid for use as a
/// reference in `LIST` and `LSUB` commands. Unless [`NameAttribute::NoSelect`] is indicated,
/// the name is also valid as an argument for commands, such as `SELECT`, that accept mailbox
/// names.
pub fn name(&self) -> &str {
self.borrow_inner().name
self.borrow_dependent().name
}
}
24 changes: 13 additions & 11 deletions src/types/response_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ use std::fmt;

use byte_pool::Block;
use imap_proto::{RequestId, Response};
use self_cell::self_cell;

#[ouroboros::self_referencing(pub_extras)]
pub struct ResponseData {
pub raw: Block<'static>,
#[borrows(raw)]
#[covariant]
response: Response<'this>,
}
self_cell!(
pub struct ResponseData {
owner: Block<'static>,

#[covariant]
dependent: Response,
}
);

impl std::cmp::PartialEq for ResponseData {
fn eq(&self, other: &Self) -> bool {
Expand All @@ -22,21 +24,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.borrow_raw().len())
.field("response", self.borrow_response())
.field("raw", &self.borrow_owner().len())
.field("response", self.borrow_dependent())
.finish()
}
}

impl ResponseData {
pub fn request_id(&self) -> Option<&RequestId> {
match self.borrow_response() {
match self.borrow_dependent() {
Response::Done { ref tag, .. } => Some(tag),
_ => None,
}
}

pub fn parsed(&self) -> &Response<'_> {
self.borrow_response()
self.borrow_dependent()
}
}

0 comments on commit 6949401

Please sign in to comment.