diff --git a/src/connection.rs b/src/connection.rs index 7a464279..5a3c795e 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -49,7 +49,7 @@ use crate::errors::{ConnectionError, ParseError, ReplyError, ReplyOrIdError}; use crate::protocol::xproto::Setup; use crate::protocol::Event; use crate::utils::RawFdContainer; -use crate::x11_utils::{ExtensionInformation, X11Error}; +use crate::x11_utils::{ExtensionInformation, TryParse, X11Error}; /// Number type used for referring to things that were sent to the server in responses from the /// server. @@ -119,7 +119,7 @@ pub trait RequestConnection { fds: Vec, ) -> Result, ConnectionError> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>; + R: TryParse; /// Send a request with a reply containing file descriptors to the server. /// @@ -496,7 +496,7 @@ pub enum DiscardMode { /// /// fn send_request_with_reply(&self, bufs: &[IoSlice], fds: Vec) /// -> Result, ConnectionError> -/// where R: for<'a> TryFrom<&'a [u8], Error=ParseError> { +/// where R: TryParse { /// Ok(Cookie::new(self, self.send_request(bufs, fds, true, false)?)) /// } /// diff --git a/src/cookie.rs b/src/cookie.rs index d621c15f..ab27e723 100644 --- a/src/cookie.rs +++ b/src/cookie.rs @@ -1,6 +1,6 @@ //! Cookies are handles to future replies or errors from the X11 server. -use std::convert::{TryFrom, TryInto}; +use std::convert::TryFrom; use std::marker::PhantomData; use crate::connection::{BufWithFds, DiscardMode, RequestConnection, RequestKind, SequenceNumber}; @@ -9,6 +9,7 @@ use crate::errors::{ConnectionError, ParseError, ReplyError}; use crate::protocol::record::EnableContextReply; use crate::protocol::xproto::ListFontsWithInfoReply; use crate::utils::RawFdContainer; +use crate::x11_utils::TryParse; /// A handle to a possible error from the X11 server. /// @@ -144,7 +145,7 @@ where impl Cookie<'_, C, R> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>, + R: TryParse, C: RequestConnection + ?Sized, { /// Construct a new cookie. @@ -177,13 +178,13 @@ where /// Get the reply that the server sent. pub fn reply(self) -> Result { - Ok(self.raw_reply()?.as_ref().try_into()?) + Ok(R::try_parse(self.raw_reply()?.as_ref())?.0) } /// Get the reply that the server sent, but have errors handled as events. pub fn reply_unchecked(self) -> Result, ConnectionError> { self.raw_reply_unchecked()? - .map(|buf| buf.as_ref().try_into()) + .map(|buf| R::try_parse(buf.as_ref()).map(|r| r.0)) .transpose() .map_err(Into::into) } diff --git a/src/extension_manager.rs b/src/extension_manager.rs index 456c3754..9c788a86 100644 --- a/src/extension_manager.rs +++ b/src/extension_manager.rs @@ -158,7 +158,7 @@ mod test { use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; use crate::errors::{ConnectionError, ParseError}; use crate::utils::RawFdContainer; - use crate::x11_utils::{ExtInfoProvider, ExtensionInformation}; + use crate::x11_utils::{ExtInfoProvider, ExtensionInformation, TryParse}; use super::{CheckState, ExtensionManager}; @@ -173,7 +173,7 @@ mod test { _fds: Vec, ) -> Result, ConnectionError> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>, + R: TryParse, { Ok(Cookie::new(self, 1)) } diff --git a/src/rust_connection/mod.rs b/src/rust_connection/mod.rs index 81e74c1a..eb829739 100644 --- a/src/rust_connection/mod.rs +++ b/src/rust_connection/mod.rs @@ -14,7 +14,7 @@ use crate::extension_manager::ExtensionManager; use crate::protocol::bigreq::{ConnectionExt as _, EnableReply}; use crate::protocol::xproto::{Setup, SetupRequest, GET_INPUT_FOCUS_REQUEST}; use crate::utils::RawFdContainer; -use crate::x11_utils::{ExtensionInformation, Serialize}; +use crate::x11_utils::{ExtensionInformation, Serialize, TryParse}; mod id_allocator; mod inner; @@ -451,7 +451,7 @@ impl RequestConnection for RustConnection { fds: Vec, ) -> Result, ConnectionError> where - Reply: for<'a> TryFrom<&'a [u8], Error = ParseError>, + Reply: TryParse, { Ok(Cookie::new( self, diff --git a/src/xcb_ffi/mod.rs b/src/xcb_ffi/mod.rs index f92a3f17..fb943a22 100644 --- a/src/xcb_ffi/mod.rs +++ b/src/xcb_ffi/mod.rs @@ -25,7 +25,7 @@ pub use crate::errors::{ConnectError, ConnectionError, ParseError, ReplyError, R use crate::extension_manager::ExtensionManager; use crate::protocol::xproto::Setup; use crate::utils::{CSlice, RawFdContainer}; -use crate::x11_utils::ExtensionInformation; +use crate::x11_utils::{ExtensionInformation, TryParse}; mod pending_errors; mod raw_ffi; @@ -356,7 +356,7 @@ impl RequestConnection for XCBConnection { fds: Vec, ) -> Result, ConnectionError> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>, + R: TryParse, { Ok(Cookie::new( self, diff --git a/tests/regression_tests.rs b/tests/regression_tests.rs index d70019bd..42493351 100644 --- a/tests/regression_tests.rs +++ b/tests/regression_tests.rs @@ -69,7 +69,7 @@ impl RequestConnection for FakeConnection { fds: Vec, ) -> Result, ConnectionError> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>, + R: TryParse, { Ok(Cookie::new(self, self.internal_send_request(bufs, fds)?)) } diff --git a/tests/resource_manager.rs b/tests/resource_manager.rs index f2ceae13..91c45108 100644 --- a/tests/resource_manager.rs +++ b/tests/resource_manager.rs @@ -149,7 +149,7 @@ mod test { _: Vec, ) -> Result, ConnectionError> where - R: for<'a> TryFrom<&'a [u8], Error = ParseError>, + R: TryParse, { Ok(Cookie::new(self, 42)) }