Compare commits

..

No commits in common. "01ee8c872b15e2aecb4c0ef5c2dd3aa6cc3c4d3c" and "fc5f09356466d51404317c1b09e19720dd50c314" have entirely different histories.

8 changed files with 39 additions and 116 deletions

32
src/proto/body.rs Normal file
View file

@ -0,0 +1,32 @@
use imap_codec::types::response::Data as ImapData;
#[derive(Debug)]
pub enum Body {
Once(Vec<ImapData>),
}
impl Body {
pub(crate) fn into_data(self) -> Vec<ImapData> {
match self {
Body::Once(data) => data,
}
}
}
impl FromIterator<ImapData> for Body {
fn from_iter<T: IntoIterator<Item = ImapData>>(iter: T) -> Self {
Body::Once(Vec::from_iter(iter))
}
}
impl From<Vec<ImapData>> for Body {
fn from(data: Vec<ImapData>) -> Self {
Body::from_iter(data)
}
}
impl From<ImapData> for Body {
fn from(data: ImapData) -> Self {
Body::from_iter([data])
}
}

View file

@ -1,5 +1,6 @@
pub use self::req::Request; pub use self::req::Request;
pub use self::res::Response; pub use self::res::Response;
pub mod body;
pub mod req; pub mod req;
pub mod res; pub mod res;

3
src/proto/req.rs Normal file
View file

@ -0,0 +1,3 @@
use imap_codec::types::command::Command;
pub type Request = Command;

View file

@ -1,5 +0,0 @@
use imap_codec::types::command::Command;
pub struct Request {
pub command: Command,
}

View file

@ -3,11 +3,9 @@ use imap_codec::types::{
response::{Code as ImapCode, Status as ImapStatus}, response::{Code as ImapCode, Status as ImapStatus},
}; };
use self::body::Body; use super::body::Body;
use crate::errors::{Error, Result}; use crate::errors::{Error, Result};
pub mod body;
#[derive(Debug)] #[derive(Debug)]
pub struct Response { pub struct Response {
pub(crate) status: Status, pub(crate) status: Status,

View file

@ -1,74 +0,0 @@
use std::io;
use imap_codec::codec::Encode;
use imap_codec::types::response::{Data as ImapData, Status as ImapStatus};
#[derive(Debug)]
pub enum Body {
Once(Vec<Data>),
}
impl Body {
pub(crate) fn into_data(self) -> Vec<Data> {
match self {
Body::Once(data) => data,
}
}
}
impl FromIterator<Data> for Body {
fn from_iter<T: IntoIterator<Item = Data>>(iter: T) -> Self {
Body::Once(Vec::from_iter(iter))
}
}
impl FromIterator<ImapData> for Body {
fn from_iter<T: IntoIterator<Item = ImapData>>(iter: T) -> Self {
Body::from_iter(iter.into_iter().map(Data::Data))
}
}
impl From<Vec<Data>> for Body {
fn from(body: Vec<Data>) -> Self {
Body::from_iter(body)
}
}
impl From<Vec<ImapData>> for Body {
fn from(data: Vec<ImapData>) -> Self {
Body::from_iter(data)
}
}
impl From<ImapData> for Body {
fn from(data: ImapData) -> Self {
Body::from_iter([data])
}
}
#[derive(Debug, Clone)]
pub enum Data {
Data(ImapData),
Status(ImapStatus),
}
impl Encode for Data {
fn encode(&self, writer: &mut impl io::Write) -> std::io::Result<()> {
match self {
Data::Data(ref data) => data.encode(writer),
Data::Status(ref status) => status.encode(writer),
}
}
}
impl From<ImapData> for Data {
fn from(data: ImapData) -> Self {
Data::Data(data)
}
}
impl From<ImapStatus> for Data {
fn from(status: ImapStatus) -> Self {
Data::Status(status)
}
}

View file

@ -157,7 +157,7 @@ where
fn call(&mut self, req: Request) -> Self::Future { fn call(&mut self, req: Request) -> Self::Future {
use futures::{FutureExt, TryFutureExt}; use futures::{FutureExt, TryFutureExt};
let tag = req.command.tag.clone(); let tag = req.tag.clone();
self.inner.call(req).map_ok(|res| (Some(tag), res)).boxed() self.inner.call(req).map_ok(|res| (Some(tag), res)).boxed()
} }

View file

@ -67,7 +67,7 @@ where
*this.read_buf = input.into(); *this.read_buf = input.into();
let req = Request { command }; let req = command;
return Poll::Ready(Some(Ok(req))); return Poll::Ready(Some(Ok(req)));
} }
} }
@ -146,35 +146,3 @@ where
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }
} }
impl<C> Sink<Response> for Connection<C>
where
Self: Sink<(Option<Tag>, Response)>,
{
type Error = <Connection<C> as Sink<(Option<Tag>, Response)>>::Error;
fn poll_ready(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
<Self as Sink<(Option<Tag>, Response)>>::poll_ready(self, cx)
}
fn start_send(self: Pin<&mut Self>, item: Response) -> Result<(), Self::Error> {
<Self as Sink<(Option<Tag>, Response)>>::start_send(self, (None, item))
}
fn poll_flush(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
<Self as Sink<(Option<Tag>, Response)>>::poll_flush(self, cx)
}
fn poll_close(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
<Self as Sink<(Option<Tag>, Response)>>::poll_close(self, cx)
}
}