From 21ea164e3ec607c520ac7133399f815020b24c59 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sun, 17 Jul 2022 19:49:54 -0400 Subject: [PATCH] Use impl AsRef instead of generics --- src/client.rs | 120 +++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/client.rs b/src/client.rs index e2f4e47..be8798d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -374,10 +374,10 @@ impl Client { /// } /// # } /// ``` - pub fn login, P: AsRef>( + pub fn login( mut self, - username: U, - password: P, + username: impl AsRef, + password: impl AsRef, ) -> ::std::result::Result, (Error, Client)> { let synopsis = "LOGIN"; let u = @@ -432,10 +432,10 @@ impl Client { /// }; /// } /// ``` - pub fn authenticate>( + pub fn authenticate( mut self, - auth_type: S, - authenticator: &A, + auth_type: impl AsRef, + authenticator: &impl Authenticator, ) -> ::std::result::Result, (Error, Client)> { ok_or_unauth_client_err!( self.run_command(&format!("AUTHENTICATE {}", auth_type.as_ref())), @@ -528,7 +528,7 @@ impl Session { /// [`Connection::run_command_and_read_response`], you *may* see additional untagged `RECENT`, /// `EXISTS`, `FETCH`, and `EXPUNGE` responses. You can get them from the /// `unsolicited_responses` channel of the [`Session`](struct.Session.html). - pub fn select>(&mut self, mailbox_name: S) -> Result { + pub fn select(&mut self, mailbox_name: impl AsRef) -> Result { self.run(&format!( "SELECT {}", validate_str("SELECT", "mailbox", mailbox_name.as_ref())? @@ -540,7 +540,7 @@ impl Session { /// however, the selected mailbox is identified as read-only. No changes to the permanent state /// of the mailbox, including per-user state, will happen in a mailbox opened with `examine`; /// in particular, messagess cannot lose [`Flag::Recent`] in an examined mailbox. - pub fn examine>(&mut self, mailbox_name: S) -> Result { + pub fn examine(&mut self, mailbox_name: impl AsRef) -> Result { self.run(&format!( "EXAMINE {}", validate_str("EXAMINE", "mailbox", mailbox_name.as_ref())? @@ -606,11 +606,11 @@ impl Session { /// - `RFC822.HEADER`: Functionally equivalent to `BODY.PEEK[HEADER]`. /// - `RFC822.SIZE`: The [RFC-2822](https://tools.ietf.org/html/rfc2822) size of the message. /// - `UID`: The unique identifier for the message. - pub fn fetch(&mut self, sequence_set: S1, query: S2) -> Result - where - S1: AsRef, - S2: AsRef, - { + pub fn fetch( + &mut self, + sequence_set: impl AsRef, + query: impl AsRef, + ) -> Result { if sequence_set.as_ref().is_empty() { Fetches::parse(vec![], &mut self.unsolicited_responses_tx) } else { @@ -626,11 +626,11 @@ impl Session { /// Equivalent to [`Session::fetch`], except that all identifiers in `uid_set` are /// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8). - pub fn uid_fetch(&mut self, uid_set: S1, query: S2) -> Result - where - S1: AsRef, - S2: AsRef, - { + pub fn uid_fetch( + &mut self, + uid_set: impl AsRef, + query: impl AsRef, + ) -> Result { if uid_set.as_ref().is_empty() { Fetches::parse(vec![], &mut self.unsolicited_responses_tx) } else { @@ -688,7 +688,7 @@ impl Session { /// the mailbox UNLESS the new incarnation has a different unique identifier validity value. /// See the description of the [`UID` /// command](https://tools.ietf.org/html/rfc3501#section-6.4.8) for more detail. - pub fn create>(&mut self, mailbox_name: S) -> Result<()> { + pub fn create(&mut self, mailbox_name: impl AsRef) -> Result<()> { self.run_command_and_check_ok(&format!( "CREATE {}", validate_str("CREATE", "mailbox", mailbox_name.as_ref())? @@ -714,7 +714,7 @@ impl Session { /// incarnation, UNLESS the new incarnation has a different unique identifier validity value. /// See the description of the [`UID` /// command](https://tools.ietf.org/html/rfc3501#section-6.4.8) for more detail. - pub fn delete>(&mut self, mailbox_name: S) -> Result<()> { + pub fn delete(&mut self, mailbox_name: impl AsRef) -> Result<()> { self.run_command_and_check_ok(&format!( "DELETE {}", validate_str("DELETE", "mailbox", mailbox_name.as_ref())? @@ -746,7 +746,7 @@ impl Session { /// to a new mailbox with the given name, leaving `INBOX` empty. If the server implementation /// supports inferior hierarchical names of `INBOX`, these are unaffected by a rename of /// `INBOX`. - pub fn rename, S2: AsRef>(&mut self, from: S1, to: S2) -> Result<()> { + pub fn rename(&mut self, from: impl AsRef, to: impl AsRef) -> Result<()> { self.run_command_and_check_ok(&format!( "RENAME {} {}", quote!(from.as_ref()), @@ -762,7 +762,7 @@ impl Session { /// The server may validate the mailbox argument to `SUBSCRIBE` to verify that it exists. /// However, it will not unilaterally remove an existing mailbox name from the subscription /// list even if a mailbox by that name no longer exists. - pub fn subscribe>(&mut self, mailbox: S) -> Result<()> { + pub fn subscribe(&mut self, mailbox: impl AsRef) -> Result<()> { self.run_command_and_check_ok(&format!("SUBSCRIBE {}", quote!(mailbox.as_ref()))) } @@ -770,7 +770,7 @@ impl Session { /// specified mailbox name from the server's set of "active" or "subscribed" mailboxes as /// returned by [`Session::lsub`]. This command returns `Ok` only if the unsubscription is /// successful. - pub fn unsubscribe>(&mut self, mailbox: S) -> Result<()> { + pub fn unsubscribe(&mut self, mailbox: impl AsRef) -> Result<()> { self.run_command_and_check_ok(&format!("UNSUBSCRIBE {}", quote!(mailbox.as_ref()))) } @@ -813,7 +813,7 @@ impl Session { /// /// Alternatively, the client may fall back to using just [`Session::expunge`], risking the /// unintended removal of some messages. - pub fn uid_expunge>(&mut self, uid_set: S) -> Result { + pub fn uid_expunge(&mut self, uid_set: impl AsRef) -> Result { self.run_command(&format!("UID EXPUNGE {}", uid_set.as_ref()))?; self.read_response() .and_then(|(lines, _)| parse_expunge(lines, &mut self.unsolicited_responses_tx)) @@ -896,11 +896,11 @@ impl Session { /// Ok(()) /// } /// ``` - pub fn store(&mut self, sequence_set: S1, query: S2) -> Result - where - S1: AsRef, - S2: AsRef, - { + pub fn store( + &mut self, + sequence_set: impl AsRef, + query: impl AsRef, + ) -> Result { self.run_command_and_read_response(&format!( "STORE {} {}", sequence_set.as_ref(), @@ -911,11 +911,11 @@ impl Session { /// Equivalent to [`Session::store`], except that all identifiers in `sequence_set` are /// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8). - pub fn uid_store(&mut self, uid_set: S1, query: S2) -> Result - where - S1: AsRef, - S2: AsRef, - { + pub fn uid_store( + &mut self, + uid_set: impl AsRef, + query: impl AsRef, + ) -> Result { self.run_command_and_read_response(&format!( "UID STORE {} {}", uid_set.as_ref(), @@ -931,10 +931,10 @@ impl Session { /// /// If the `COPY` command is unsuccessful for any reason, the server restores the destination /// mailbox to its state before the `COPY` attempt. - pub fn copy, S2: AsRef>( + pub fn copy( &mut self, - sequence_set: S1, - mailbox_name: S2, + sequence_set: impl AsRef, + mailbox_name: impl AsRef, ) -> Result<()> { self.run_command_and_check_ok(&format!( "COPY {} {}", @@ -945,10 +945,10 @@ impl Session { /// Equivalent to [`Session::copy`], except that all identifiers in `sequence_set` are /// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8). - pub fn uid_copy, S2: AsRef>( + pub fn uid_copy( &mut self, - uid_set: S1, - mailbox_name: S2, + uid_set: impl AsRef, + mailbox_name: impl AsRef, ) -> Result<()> { self.run_command_and_check_ok(&format!( "UID COPY {} {}", @@ -987,10 +987,10 @@ impl Session { /// orphaned). The server will generally not leave any message in both mailboxes (it would be /// bad for a partial failure to result in a bunch of duplicate messages). This is true even /// if the server returns with [`Error::No`]. - pub fn mv, S2: AsRef>( + pub fn mv( &mut self, - sequence_set: S1, - mailbox_name: S2, + sequence_set: impl AsRef, + mailbox_name: impl AsRef, ) -> Result<()> { self.run_command_and_check_ok(&format!( "MOVE {} {}", @@ -1003,10 +1003,10 @@ impl Session { /// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8) /// and the [semantics of `MOVE` and `UID /// MOVE`](https://tools.ietf.org/html/rfc6851#section-3.3). - pub fn uid_mv, S2: AsRef>( + pub fn uid_mv( &mut self, - uid_set: S1, - mailbox_name: S2, + uid_set: impl AsRef, + mailbox_name: impl AsRef, ) -> Result<()> { self.run_command_and_check_ok(&format!( "UID MOVE {} {}", @@ -1121,10 +1121,10 @@ impl Session { /// - `UNSEEN`: The number of messages which do not have [`Flag::Seen`] set. /// /// `data_items` is a space-separated list enclosed in parentheses. - pub fn status, S2: AsRef>( + pub fn status( &mut self, - mailbox_name: S1, - data_items: S2, + mailbox_name: impl AsRef, + data_items: impl AsRef, ) -> Result { let mailbox_name = mailbox_name.as_ref(); self.run_command_and_read_response(&format!( @@ -1233,7 +1233,7 @@ impl Session { /// /// - `BEFORE `: Messages whose internal date (disregarding time and timezone) is earlier than the specified date. /// - `SINCE `: Messages whose internal date (disregarding time and timezone) is within or later than the specified date. - pub fn search>(&mut self, query: S) -> Result> { + pub fn search(&mut self, query: impl AsRef) -> Result> { self.run_command_and_read_response(&format!("SEARCH {}", query.as_ref())) .and_then(|lines| parse_id_set(&lines, &mut self.unsolicited_responses_tx)) } @@ -1241,7 +1241,7 @@ impl Session { /// Equivalent to [`Session::search`], except that the returned identifiers /// are [`Uid`] instead of [`Seq`]. See also the [`UID` /// command](https://tools.ietf.org/html/rfc3501#section-6.4.8). - pub fn uid_search>(&mut self, query: S) -> Result> { + pub fn uid_search(&mut self, query: impl AsRef) -> Result> { self.run_command_and_read_response(&format!("UID SEARCH {}", query.as_ref())) .and_then(|lines| parse_id_set(&lines, &mut self.unsolicited_responses_tx)) } @@ -1251,11 +1251,11 @@ impl Session { /// /// This command is like [`Session::search`], except that /// the results are also sorted according to the supplied criteria (subject to the given charset). - pub fn sort>( + pub fn sort( &mut self, criteria: &[extensions::sort::SortCriterion<'_>], charset: extensions::sort::SortCharset<'_>, - query: S, + query: impl AsRef, ) -> Result> { self.run_command_and_read_response(&format!( "SORT {} {} {}", @@ -1269,11 +1269,11 @@ impl Session { /// Equivalent to [`Session::sort`], except that it returns [`Uid`]s. /// /// See also [`Session::uid_search`]. - pub fn uid_sort>( + pub fn uid_sort( &mut self, criteria: &[extensions::sort::SortCriterion<'_>], charset: extensions::sort::SortCharset<'_>, - query: S, + query: impl AsRef, ) -> Result> { self.run_command_and_read_response(&format!( "UID SORT {} {} {}", @@ -1286,12 +1286,12 @@ impl Session { // these are only here because they are public interface, the rest is in `Connection` /// Runs a command and checks if it returns OK. - pub fn run_command_and_check_ok>(&mut self, command: S) -> Result<()> { + pub fn run_command_and_check_ok(&mut self, command: impl AsRef) -> Result<()> { self.run_command_and_read_response(command).map(|_| ()) } /// Runs any command passed to it. - pub fn run_command>(&mut self, untagged_command: S) -> Result<()> { + pub fn run_command(&mut self, untagged_command: impl AsRef) -> Result<()> { self.conn.run_command(untagged_command.as_ref()) } @@ -1303,7 +1303,7 @@ impl Session { /// additional untagged `RECENT`, `EXISTS`, `FETCH`, and `EXPUNGE` responses! /// /// The response includes the final [`Response::Done`], which starts at the returned index. - pub fn run>(&mut self, untagged_command: S) -> Result<(Vec, usize)> { + pub fn run(&mut self, untagged_command: impl AsRef) -> Result<(Vec, usize)> { self.conn.run(untagged_command.as_ref()) } @@ -1315,9 +1315,9 @@ impl Session { /// additional untagged `RECENT`, `EXISTS`, `FETCH`, and `EXPUNGE` responses! /// /// The response does not include the final [`Response::Done`]. - pub fn run_command_and_read_response>( + pub fn run_command_and_read_response( &mut self, - untagged_command: S, + untagged_command: impl AsRef, ) -> Result> { let (mut data, ok) = self.run(untagged_command)?; data.truncate(ok);