Skip to content

Commit 9b5c678

Browse files
committed
Update async-std, stop-token, migrate to stable channels
1 parent 0823e7f commit 9b5c678

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ nom = "5.0"
2727
base64 = "0.13"
2828
chrono = "0.4"
2929
async-native-tls = { version = "0.3.3" }
30-
async-std = { version = "1.6.0", default-features = false, features = ["std"] }
30+
async-std = { version = "1.8.0", default-features = false, features = ["std"] }
3131
pin-utils = "0.1.0-alpha.4"
3232
futures = "0.3.0"
3333
rental = "0.5.5"
34-
stop-token = { version = "0.1.1", features = ["unstable"] }
34+
stop-token = "0.2"
3535
byte-pool = "0.2.2"
3636
lazy_static = "1.4.0"
3737
log = "0.4.8"
@@ -41,7 +41,7 @@ thiserror = "1.0.9"
4141
lettre_email = "0.9"
4242
pretty_assertions = "0.6.1"
4343
async-smtp = { version = "0.3.0" }
44-
async-std = { version = "1.6.0", default-features = false, features = ["std", "attributes"] }
44+
async-std = { version = "1.8.0", default-features = false, features = ["std", "attributes"] }
4545

4646
[[example]]
4747
name = "basic"

src/client.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::pin::Pin;
55
use std::str;
66

77
use async_native_tls::{TlsConnector, TlsStream};
8+
use async_std::channel;
89
use async_std::io::{self, Read, Write};
910
use async_std::net::{TcpStream, ToSocketAddrs};
1011
use async_std::prelude::*;
11-
use async_std::sync;
1212
use imap_proto::{RequestId, Response};
1313

1414
use super::authenticator::Authenticator;
@@ -36,11 +36,11 @@ macro_rules! quote {
3636
#[derive(Debug)]
3737
pub struct Session<T: Read + Write + Unpin + fmt::Debug> {
3838
pub(crate) conn: Connection<T>,
39-
pub(crate) unsolicited_responses_tx: sync::Sender<UnsolicitedResponse>,
39+
pub(crate) unsolicited_responses_tx: channel::Sender<UnsolicitedResponse>,
4040

4141
/// Server responses that are not related to the current command. See also the note on
4242
/// [unilateral server responses in RFC 3501](https://tools.ietf.org/html/rfc3501#section-7).
43-
pub unsolicited_responses: sync::Receiver<UnsolicitedResponse>,
43+
pub unsolicited_responses: channel::Receiver<UnsolicitedResponse>,
4444
}
4545

4646
impl<T: Read + Write + Unpin + fmt::Debug> Unpin for Session<T> {}
@@ -358,7 +358,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
358358

359359
// not public, just to avoid duplicating the channel creation code
360360
fn new(conn: Connection<T>) -> Self {
361-
let (tx, rx) = sync::channel(100);
361+
let (tx, rx) = channel::bounded(100);
362362
Session {
363363
conn,
364364
unsolicited_responses: rx,
@@ -1313,7 +1313,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
13131313
pub async fn run_command_and_check_ok(
13141314
&mut self,
13151315
command: &str,
1316-
unsolicited: Option<sync::Sender<UnsolicitedResponse>>,
1316+
unsolicited: Option<channel::Sender<UnsolicitedResponse>>,
13171317
) -> Result<()> {
13181318
let id = self.run_command(command).await?;
13191319
self.check_done_ok(&id, unsolicited).await?;
@@ -1324,7 +1324,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
13241324
pub(crate) async fn check_done_ok(
13251325
&mut self,
13261326
id: &RequestId,
1327-
unsolicited: Option<sync::Sender<UnsolicitedResponse>>,
1327+
unsolicited: Option<channel::Sender<UnsolicitedResponse>>,
13281328
) -> Result<()> {
13291329
if let Some(first_res) = self.stream.next().await {
13301330
self.check_done_ok_from(id, unsolicited, first_res?).await
@@ -1336,7 +1336,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
13361336
pub(crate) async fn check_done_ok_from(
13371337
&mut self,
13381338
id: &RequestId,
1339-
unsolicited: Option<sync::Sender<UnsolicitedResponse>>,
1339+
unsolicited: Option<channel::Sender<UnsolicitedResponse>>,
13401340
mut response: ResponseData,
13411341
) -> Result<()> {
13421342
loop {
@@ -1495,7 +1495,7 @@ mod tests {
14951495
let client = mock_client!(mock_stream);
14961496
enum Authenticate {
14971497
Auth,
1498-
};
1498+
}
14991499
impl Authenticator for &Authenticate {
15001500
type Response = Vec<u8>;
15011501
fn process(&mut self, challenge: &[u8]) -> Self::Response {

src/parse.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::collections::HashSet;
22

3+
use async_std::channel;
34
use async_std::io;
45
use async_std::prelude::*;
56
use async_std::stream::Stream;
6-
use async_std::sync;
77
use imap_proto::{self, MailboxDatum, RequestId, Response};
88

99
use crate::error::{Error, Result};
@@ -12,7 +12,7 @@ use crate::types::*;
1212

1313
pub(crate) fn parse_names<'a, T: Stream<Item = io::Result<ResponseData>> + Unpin + Send>(
1414
stream: &'a mut T,
15-
unsolicited: sync::Sender<UnsolicitedResponse>,
15+
unsolicited: channel::Sender<UnsolicitedResponse>,
1616
command_tag: RequestId,
1717
) -> impl Stream<Item = Result<Name>> + 'a + Send + Unpin {
1818
use futures::{FutureExt, StreamExt};
@@ -58,7 +58,7 @@ fn filter_sync(res: &io::Result<ResponseData>, command_tag: &RequestId) -> bool
5858

5959
pub(crate) fn parse_fetches<'a, T: Stream<Item = io::Result<ResponseData>> + Unpin + Send>(
6060
stream: &'a mut T,
61-
unsolicited: sync::Sender<UnsolicitedResponse>,
61+
unsolicited: channel::Sender<UnsolicitedResponse>,
6262
command_tag: RequestId,
6363
) -> impl Stream<Item = Result<Fetch>> + 'a + Send + Unpin {
6464
use futures::{FutureExt, StreamExt};
@@ -87,7 +87,7 @@ pub(crate) fn parse_fetches<'a, T: Stream<Item = io::Result<ResponseData>> + Unp
8787

8888
pub(crate) fn parse_expunge<'a, T: Stream<Item = io::Result<ResponseData>> + Unpin + Send>(
8989
stream: &'a mut T,
90-
unsolicited: sync::Sender<UnsolicitedResponse>,
90+
unsolicited: channel::Sender<UnsolicitedResponse>,
9191
command_tag: RequestId,
9292
) -> impl Stream<Item = Result<u32>> + 'a + Send {
9393
use futures::StreamExt;
@@ -115,7 +115,7 @@ pub(crate) fn parse_expunge<'a, T: Stream<Item = io::Result<ResponseData>> + Unp
115115

116116
pub(crate) async fn parse_capabilities<'a, T: Stream<Item = io::Result<ResponseData>> + Unpin>(
117117
stream: &'a mut T,
118-
unsolicited: sync::Sender<UnsolicitedResponse>,
118+
unsolicited: channel::Sender<UnsolicitedResponse>,
119119
command_tag: RequestId,
120120
) -> Result<Capabilities> {
121121
let mut caps: HashSet<Capability> = HashSet::new();
@@ -143,7 +143,7 @@ pub(crate) async fn parse_capabilities<'a, T: Stream<Item = io::Result<ResponseD
143143

144144
pub(crate) async fn parse_noop<T: Stream<Item = io::Result<ResponseData>> + Unpin>(
145145
stream: &mut T,
146-
unsolicited: sync::Sender<UnsolicitedResponse>,
146+
unsolicited: channel::Sender<UnsolicitedResponse>,
147147
command_tag: RequestId,
148148
) -> Result<()> {
149149
while let Some(resp) = stream
@@ -160,7 +160,7 @@ pub(crate) async fn parse_noop<T: Stream<Item = io::Result<ResponseData>> + Unpi
160160

161161
pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + Unpin>(
162162
stream: &mut T,
163-
unsolicited: sync::Sender<UnsolicitedResponse>,
163+
unsolicited: channel::Sender<UnsolicitedResponse>,
164164
command_tag: RequestId,
165165
) -> Result<Mailbox> {
166166
let mut mailbox = Mailbox::default();
@@ -252,7 +252,7 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
252252

253253
pub(crate) async fn parse_ids<T: Stream<Item = io::Result<ResponseData>> + Unpin>(
254254
stream: &mut T,
255-
unsolicited: sync::Sender<UnsolicitedResponse>,
255+
unsolicited: channel::Sender<UnsolicitedResponse>,
256256
command_tag: RequestId,
257257
) -> Result<HashSet<u32>> {
258258
let mut ids: HashSet<u32> = HashSet::new();
@@ -282,7 +282,7 @@ pub(crate) async fn parse_ids<T: Stream<Item = io::Result<ResponseData>> + Unpin
282282
// (see Section 7 of RFC 3501):
283283
pub(crate) async fn handle_unilateral(
284284
res: ResponseData,
285-
unsolicited: sync::Sender<UnsolicitedResponse>,
285+
unsolicited: channel::Sender<UnsolicitedResponse>,
286286
) {
287287
// ignore these if they are not being consumed
288288
if unsolicited.is_full() {
@@ -291,7 +291,7 @@ pub(crate) async fn handle_unilateral(
291291

292292
match res.parsed() {
293293
Response::MailboxData(MailboxDatum::Status { mailbox, status }) => {
294-
unsolicited
294+
let _ = unsolicited
295295
.send(UnsolicitedResponse::Status {
296296
mailbox: (*mailbox).into(),
297297
attributes: status
@@ -307,19 +307,23 @@ pub(crate) async fn handle_unilateral(
307307
})
308308
.collect(),
309309
})
310-
.await;
310+
.await; //TODO: decide what to do with result
311311
}
312312
Response::MailboxData(MailboxDatum::Recent(n)) => {
313-
unsolicited.send(UnsolicitedResponse::Recent(*n)).await;
313+
//TODO: decide what to do with result
314+
let _ = unsolicited.send(UnsolicitedResponse::Recent(*n)).await;
314315
}
315316
Response::MailboxData(MailboxDatum::Exists(n)) => {
316-
unsolicited.send(UnsolicitedResponse::Exists(*n)).await;
317+
//TODO: decide what to do with result
318+
let _ = unsolicited.send(UnsolicitedResponse::Exists(*n)).await;
317319
}
318320
Response::Expunge(n) => {
319-
unsolicited.send(UnsolicitedResponse::Expunge(*n)).await;
321+
//TODO: decide what to do with result
322+
let _ = unsolicited.send(UnsolicitedResponse::Expunge(*n)).await;
320323
}
321324
_ => {
322-
unsolicited.send(UnsolicitedResponse::Other(res)).await;
325+
//TODO: decide what to do with result
326+
let _ = unsolicited.send(UnsolicitedResponse::Other(res)).await;
323327
}
324328
}
325329
}
@@ -350,7 +354,7 @@ mod tests {
350354
input_stream(&["* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n"]);
351355

352356
let mut stream = async_std::stream::from_iter(responses);
353-
let (send, recv) = sync::channel(10);
357+
let (send, recv) = channel::bounded(10);
354358
let id = RequestId("A0001".into());
355359
let capabilities = parse_capabilities(&mut stream, send, id).await.unwrap();
356360
// shouldn't be any unexpected responses parsed
@@ -368,7 +372,7 @@ mod tests {
368372
let responses = input_stream(&["* CAPABILITY IMAP4REV1 STARTTLS\r\n"]);
369373
let mut stream = async_std::stream::from_iter(responses);
370374

371-
let (send, recv) = sync::channel(10);
375+
let (send, recv) = channel::bounded(10);
372376
let id = RequestId("A0001".into());
373377
let capabilities = parse_capabilities(&mut stream, send, id).await.unwrap();
374378

@@ -383,7 +387,7 @@ mod tests {
383387
#[async_std::test]
384388
#[should_panic]
385389
async fn parse_capability_invalid_test() {
386-
let (send, recv) = sync::channel(10);
390+
let (send, recv) = channel::bounded(10);
387391
let responses = input_stream(&["* JUNK IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n"]);
388392
let mut stream = async_std::stream::from_iter(responses);
389393

@@ -396,7 +400,7 @@ mod tests {
396400

397401
#[async_std::test]
398402
async fn parse_names_test() {
399-
let (send, recv) = sync::channel(10);
403+
let (send, recv) = channel::bounded(10);
400404
let responses = input_stream(&["* LIST (\\HasNoChildren) \".\" \"INBOX\"\r\n"]);
401405
let mut stream = async_std::stream::from_iter(responses);
402406

@@ -417,7 +421,7 @@ mod tests {
417421

418422
#[async_std::test]
419423
async fn parse_fetches_empty() {
420-
let (send, recv) = sync::channel(10);
424+
let (send, recv) = channel::bounded(10);
421425
let responses = input_stream(&[]);
422426
let mut stream = async_std::stream::from_iter(responses);
423427
let id = RequestId("a".into());
@@ -432,7 +436,7 @@ mod tests {
432436

433437
#[async_std::test]
434438
async fn parse_fetches_test() {
435-
let (send, recv) = sync::channel(10);
439+
let (send, recv) = channel::bounded(10);
436440
let responses = input_stream(&[
437441
"* 24 FETCH (FLAGS (\\Seen) UID 4827943)\r\n",
438442
"* 25 FETCH (FLAGS (\\Seen))\r\n",
@@ -462,7 +466,7 @@ mod tests {
462466
#[async_std::test]
463467
async fn parse_fetches_w_unilateral() {
464468
// https://github.com/mattnenterprise/rust-imap/issues/81
465-
let (send, recv) = sync::channel(10);
469+
let (send, recv) = channel::bounded(10);
466470
let responses = input_stream(&["* 37 FETCH (UID 74)\r\n", "* 1 RECENT\r\n"]);
467471
let mut stream = async_std::stream::from_iter(responses);
468472
let id = RequestId("a".into());
@@ -480,7 +484,7 @@ mod tests {
480484

481485
#[async_std::test]
482486
async fn parse_names_w_unilateral() {
483-
let (send, recv) = sync::channel(10);
487+
let (send, recv) = channel::bounded(10);
484488
let responses = input_stream(&[
485489
"* LIST (\\HasNoChildren) \".\" \"INBOX\"\r\n",
486490
"* 4 EXPUNGE\r\n",
@@ -506,7 +510,7 @@ mod tests {
506510

507511
#[async_std::test]
508512
async fn parse_capabilities_w_unilateral() {
509-
let (send, recv) = sync::channel(10);
513+
let (send, recv) = channel::bounded(10);
510514
let responses = input_stream(&[
511515
"* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n",
512516
"* STATUS dev.github (MESSAGES 10 UIDNEXT 11 UIDVALIDITY 1408806928 UNSEEN 0)\r\n",
@@ -541,7 +545,7 @@ mod tests {
541545

542546
#[async_std::test]
543547
async fn parse_ids_w_unilateral() {
544-
let (send, recv) = sync::channel(10);
548+
let (send, recv) = channel::bounded(10);
545549
let responses = input_stream(&[
546550
"* SEARCH 23 42 4711\r\n",
547551
"* 1 RECENT\r\n",
@@ -571,7 +575,7 @@ mod tests {
571575

572576
#[async_std::test]
573577
async fn parse_ids_test() {
574-
let (send, recv) = sync::channel(10);
578+
let (send, recv) = channel::bounded(10);
575579
let responses = input_stream(&[
576580
"* SEARCH 1600 1698 1739 1781 1795 1885 1891 1892 1893 1898 1899 1901 1911 1926 1932 1933 1993 1994 2007 2032 2033 2041 2053 2062 2063 2065 2066 2072 2078 2079 2082 2084 2095 2100 2101 2102 2103 2104 2107 2116 2120 2135 2138 2154 2163 2168 2172 2189 2193 2198 2199 2205 2212 2213 2221 2227 2267 2275 2276 2295 2300 2328 2330 2332 2333 2334\r\n",
577581
"* SEARCH 2335 2336 2337 2338 2339 2341 2342 2347 2349 2350 2358 2359 2362 2369 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2390 2392 2397 2400 2401 2403 2405 2409 2411 2414 2417 2419 2420 2424 2426 2428 2439 2454 2456 2467 2468 2469 2490 2515 2519 2520 2521\r\n",
@@ -604,7 +608,7 @@ mod tests {
604608

605609
#[async_std::test]
606610
async fn parse_ids_search() {
607-
let (send, recv) = sync::channel(10);
611+
let (send, recv) = channel::bounded(10);
608612
let responses = input_stream(&["* SEARCH\r\n"]);
609613
let mut stream = async_std::stream::from_iter(responses);
610614

0 commit comments

Comments
 (0)