From 42aa0e3350599518b005c8c06b4aa756d0bc683e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Dec 2020 13:01:53 +0100 Subject: [PATCH 1/4] Some minor improvements to the docs in x11rb::errors Signed-off-by: Uli Schlachter --- src/errors.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 9705b0e2..2f66a2fa 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -102,7 +102,7 @@ pub enum ConnectError { /// /// One situation were this error is used when libxcb indicates an error that does not match /// any of the defined error conditions. Thus, libxcb is violating its own API (or new error - /// cases were defined, but are not yet handled by x11rb) + /// cases were defined, but are not yet handled by x11rb). UnknownError, /// Error while parsing some data, see `ParseError`. @@ -115,10 +115,10 @@ pub enum ConnectError { /// Error during parsing of display string. /// - /// This is `XCB_CONN_CLOSSED_PARSE_ERR`. + /// This is `XCB_CONN_CLOSED_PARSE_ERR`. DisplayParsingError, - /// Server does not have a screen matcing the display. + /// Server does not have a screen matching the display. /// /// This is `XCB_CONN_CLOSED_INVALID_SCREEN`. InvalidScreen, @@ -133,7 +133,7 @@ pub enum ConnectError { /// The server rejected the connection with a `SetupAuthenticate` message. SetupAuthenticate(SetupAuthenticate), - /// + /// The server rejected the connection with a `SetupFailed` message. SetupFailed(SetupFailed), } @@ -188,7 +188,7 @@ pub enum ConnectionError { /// /// One situation were this error is used when libxcb indicates an error that does not match /// any of the defined error conditions. Thus, libxcb is violating its own API (or new error - /// cases were defined, but are not yet handled by x11rb) + /// cases were defined, but are not yet handled by x11rb). UnknownError, /// An X11 extension was not supported by the server. @@ -253,7 +253,7 @@ impl From for ConnectionError { pub enum ReplyError { /// Some error occurred on the X11 connection. ConnectionError(ConnectionError), - /// The X11 server sent an error in response to the request. + /// The X11 server sent an error in response to a request. X11Error(X11Error), } @@ -299,7 +299,7 @@ pub enum ReplyOrIdError { IdsExhausted, /// Some error occurred on the X11 connection. ConnectionError(ConnectionError), - /// The X11 server sent an error in response to a XC-MISC request. + /// The X11 server sent an error in response to a request. X11Error(X11Error), } From 9efb03b306d8ae88936a5ba8dc9e26d10a738e6b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Dec 2020 14:14:21 +0100 Subject: [PATCH 2/4] Generated code: Simpler conversion to usize This commit adds a crate-internal trait that allows to shorten x.try_into().or(Err(ParseError::ConversionFailed)) to x.try_to_usize(). This also makes the code generator use this new trait/function. Thanks to this change, many of the affected expressions now actually fit into a single line on my screen! Signed-off-by: Uli Schlachter --- generator/src/generator/namespace.rs | 6 +- src/protocol/bigreq.rs | 2 +- src/protocol/composite.rs | 2 +- src/protocol/damage.rs | 2 +- src/protocol/dpms.rs | 2 +- src/protocol/dri2.rs | 12 +- src/protocol/dri3.rs | 10 +- src/protocol/ge.rs | 2 +- src/protocol/glx.rs | 144 +++++++++---------- src/protocol/present.rs | 2 +- src/protocol/randr.rs | 94 ++++++------- src/protocol/record.rs | 18 +-- src/protocol/render.rs | 34 ++--- src/protocol/res.rs | 18 +-- src/protocol/screensaver.rs | 2 +- src/protocol/shape.rs | 4 +- src/protocol/shm.rs | 2 +- src/protocol/sync.rs | 6 +- src/protocol/xc_misc.rs | 4 +- src/protocol/xevie.rs | 2 +- src/protocol/xf86dri.rs | 12 +- src/protocol/xf86vidmode.rs | 40 +++--- src/protocol/xfixes.rs | 18 +-- src/protocol/xinerama.rs | 4 +- src/protocol/xinput.rs | 200 +++++++++++++-------------- src/protocol/xkb.rs | 182 ++++++++++++------------ src/protocol/xprint.rs | 32 ++--- src/protocol/xproto.rs | 104 +++++++------- src/protocol/xselinux.rs | 50 +++---- src/protocol/xtest.rs | 2 +- src/protocol/xv.rs | 28 ++-- src/protocol/xvmc.rs | 12 +- src/x11_utils.rs | 19 +++ 33 files changed, 545 insertions(+), 526 deletions(-) diff --git a/generator/src/generator/namespace.rs b/generator/src/generator/namespace.rs index f5c476d7..8adc3613 100644 --- a/generator/src/generator/namespace.rs +++ b/generator/src/generator/namespace.rs @@ -543,7 +543,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> { outln!(out, "#[allow(unused_imports)]"); outln!( out, - "use crate::x11_utils::{{Request, RequestHeader, Serialize, TryParse, TryParseFd}};" + "use crate::x11_utils::{{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}};" ); outln!( out, @@ -4056,7 +4056,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> { outln!( out, "let ({}, remaining) = crate::x11_utils::parse_u8_list({}, \ - {}.try_into().or(Err(ParseError::ConversionFailed))?)?;", + {}.try_to_usize()?)?;", rust_field_name, from, self.expr_to_str( @@ -4098,7 +4098,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> { outln!( out, "let ({}, remaining) = crate::x11_utils::parse_list::<{}>(remaining, \ - {}.try_into().or(Err(ParseError::ConversionFailed))?)?;", + {}.try_to_usize()?)?;", rust_field_name, rust_element_type, self.expr_to_str( diff --git a/src/protocol/bigreq.rs b/src/protocol/bigreq.rs index b0fd8b3d..e9eeced0 100644 --- a/src/protocol/bigreq.rs +++ b/src/protocol/bigreq.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/composite.rs b/src/protocol/composite.rs index 7143eef2..a87fa336 100644 --- a/src/protocol/composite.rs +++ b/src/protocol/composite.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/damage.rs b/src/protocol/damage.rs index e7e24215..bae37c7f 100644 --- a/src/protocol/damage.rs +++ b/src/protocol/damage.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/dpms.rs b/src/protocol/dpms.rs index 973e95d5..b897aaec 100644 --- a/src/protocol/dpms.rs +++ b/src/protocol/dpms.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/dri2.rs b/src/protocol/dri2.rs index fe86ed85..96683baf 100644 --- a/src/protocol/dri2.rs +++ b/src/protocol/dri2.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -509,11 +509,11 @@ impl TryParse for ConnectReply { let (driver_name_length, remaining) = u32::try_parse(remaining)?; let (device_name_length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, driver_name_length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, driver_name_length.try_to_usize()?)?; let driver_name = driver_name.to_vec(); - let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (driver_name_length.checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(driver_name_length).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (driver_name_length.checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(driver_name_length).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let alignment_pad = alignment_pad.to_vec(); - let (device_name, remaining) = crate::x11_utils::parse_u8_list(remaining, device_name_length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (device_name, remaining) = crate::x11_utils::parse_u8_list(remaining, device_name_length.try_to_usize()?)?; let device_name = device_name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -911,7 +911,7 @@ impl TryParse for GetBuffersReply { let (height, remaining) = u32::try_parse(remaining)?; let (count, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (buffers, remaining) = crate::x11_utils::parse_list::(remaining, count.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (buffers, remaining) = crate::x11_utils::parse_list::(remaining, count.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1181,7 +1181,7 @@ impl TryParse for GetBuffersWithFormatReply { let (height, remaining) = u32::try_parse(remaining)?; let (count, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (buffers, remaining) = crate::x11_utils::parse_list::(remaining, count.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (buffers, remaining) = crate::x11_utils::parse_list::(remaining, count.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/dri3.rs b/src/protocol/dri3.rs index 360c172e..23cd2a39 100644 --- a/src/protocol/dri3.rs +++ b/src/protocol/dri3.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -783,8 +783,8 @@ impl TryParse for GetSupportedModifiersReply { let (num_window_modifiers, remaining) = u32::try_parse(remaining)?; let (num_screen_modifiers, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (window_modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_window_modifiers.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (screen_modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_screen_modifiers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (window_modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_window_modifiers.try_to_usize()?)?; + let (screen_modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_screen_modifiers.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1125,8 +1125,8 @@ impl TryParseFd for BuffersFromPixmapReply { let (depth, remaining) = u8::try_parse(remaining)?; let (bpp, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(6..).ok_or(ParseError::InsufficientData)?; - let (strides, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (strides, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_to_usize()?)?; + let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_to_usize()?)?; let fds_len = usize::try_from(nfd).or(Err(ParseError::ConversionFailed))?; if fds.len() < fds_len { return Err(ParseError::MissingFileDescriptors) } let mut buffers = fds.split_off(fds_len); diff --git a/src/protocol/ge.rs b/src/protocol/ge.rs index fbea3958..204c6d01 100644 --- a/src/protocol/ge.rs +++ b/src/protocol/ge.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/glx.rs b/src/protocol/glx.rs index 506e334c..cb620edf 100644 --- a/src/protocol/glx.rs +++ b/src/protocol/glx.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -545,7 +545,7 @@ impl<'input> RenderLargeRequest<'input> { let (request_num, remaining) = u16::try_parse(remaining)?; let (request_total, remaining) = u16::try_parse(remaining)?; let (data_len, remaining) = u32::try_parse(remaining)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.try_to_usize()?)?; let _ = remaining; Ok(RenderLargeRequest { context_tag, @@ -1722,7 +1722,7 @@ impl TryParse for GetVisualConfigsReply { let (num_visuals, remaining) = u32::try_parse(remaining)?; let (num_properties, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (property_list, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (property_list, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2015,7 +2015,7 @@ impl TryParse for VendorPrivateWithReplyReply { let (retval, remaining) = u32::try_parse(remaining)?; let (data1, remaining) = crate::x11_utils::parse_u8_list(remaining, 24)?; let data1 = <[u8; 24]>::try_from(data1).unwrap(); - let (data2, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data2, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data2 = data2.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2238,7 +2238,7 @@ impl TryParse for QueryServerStringReply { let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; let (str_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, str_len.try_to_usize()?)?; let string = string.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2336,7 +2336,7 @@ impl<'input> ClientInfoRequest<'input> { let (major_version, remaining) = u32::try_parse(value)?; let (minor_version, remaining) = u32::try_parse(remaining)?; let (str_len, remaining) = u32::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, str_len.try_to_usize()?)?; let _ = remaining; Ok(ClientInfoRequest { major_version, @@ -2450,7 +2450,7 @@ impl TryParse for GetFBConfigsReply { let (num_fb_configs, remaining) = u32::try_parse(remaining)?; let (num_properties, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (property_list, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (property_list, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2563,7 +2563,7 @@ impl<'input> CreatePixmapRequest<'input> { let (pixmap, remaining) = xproto::Pixmap::try_parse(remaining)?; let (glx_pixmap, remaining) = Pixmap::try_parse(remaining)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(CreatePixmapRequest { screen, @@ -2857,7 +2857,7 @@ impl TryParse for QueryContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3088,7 +3088,7 @@ impl<'input> CreatePbufferRequest<'input> { let (fbconfig, remaining) = Fbconfig::try_parse(remaining)?; let (pbuffer, remaining) = Pbuffer::try_parse(remaining)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(CreatePbufferRequest { screen, @@ -3268,7 +3268,7 @@ impl TryParse for GetDrawableAttributesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3361,7 +3361,7 @@ impl<'input> ChangeDrawableAttributesRequest<'input> { } let (drawable, remaining) = Drawable::try_parse(value)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangeDrawableAttributesRequest { drawable, @@ -3470,7 +3470,7 @@ impl<'input> CreateWindowRequest<'input> { let (window, remaining) = xproto::Window::try_parse(remaining)?; let (glx_window, remaining) = Window::try_parse(remaining)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(CreateWindowRequest { screen, @@ -3657,9 +3657,9 @@ impl<'input> SetClientInfoARBRequest<'input> { let (num_versions, remaining) = u32::try_parse(remaining)?; let (gl_str_len, remaining) = u32::try_parse(remaining)?; let (glx_str_len, remaining) = u32::try_parse(remaining)?; - let (gl_versions, remaining) = crate::x11_utils::parse_list::(remaining, num_versions.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (gl_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, gl_str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (glx_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, glx_str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (gl_versions, remaining) = crate::x11_utils::parse_list::(remaining, num_versions.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; + let (gl_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, gl_str_len.try_to_usize()?)?; + let (glx_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, glx_str_len.try_to_usize()?)?; let _ = remaining; Ok(SetClientInfoARBRequest { major_version, @@ -3785,7 +3785,7 @@ impl<'input> CreateContextAttribsARBRequest<'input> { let (is_direct, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; let (num_attribs, remaining) = u32::try_parse(remaining)?; - let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attribs, remaining) = crate::x11_utils::parse_list::(remaining, num_attribs.checked_mul(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(CreateContextAttribsARBRequest { context, @@ -3910,9 +3910,9 @@ impl<'input> SetClientInfo2ARBRequest<'input> { let (num_versions, remaining) = u32::try_parse(remaining)?; let (gl_str_len, remaining) = u32::try_parse(remaining)?; let (glx_str_len, remaining) = u32::try_parse(remaining)?; - let (gl_versions, remaining) = crate::x11_utils::parse_list::(remaining, num_versions.checked_mul(3u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (gl_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, gl_str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (glx_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, glx_str_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (gl_versions, remaining) = crate::x11_utils::parse_list::(remaining, num_versions.checked_mul(3u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; + let (gl_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, gl_str_len.try_to_usize()?)?; + let (glx_extension_string, remaining) = crate::x11_utils::parse_u8_list(remaining, glx_str_len.try_to_usize()?)?; let _ = remaining; Ok(SetClientInfo2ARBRequest { major_version, @@ -4536,7 +4536,7 @@ impl TryParse for RenderModeReply { let (n, remaining) = u32::try_parse(remaining)?; let (new_mode, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5029,7 +5029,7 @@ impl TryParse for ReadPixelsReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -5156,7 +5156,7 @@ impl TryParse for GetBooleanvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5276,7 +5276,7 @@ impl TryParse for GetClipPlaneReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5402,7 +5402,7 @@ impl TryParse for GetDoublevReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float64::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5623,7 +5623,7 @@ impl TryParse for GetFloatvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5748,7 +5748,7 @@ impl TryParse for GetIntegervReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5882,7 +5882,7 @@ impl TryParse for GetLightfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6016,7 +6016,7 @@ impl TryParse for GetLightivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6150,7 +6150,7 @@ impl TryParse for GetMapdvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float64::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6284,7 +6284,7 @@ impl TryParse for GetMapfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6418,7 +6418,7 @@ impl TryParse for GetMapivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6552,7 +6552,7 @@ impl TryParse for GetMaterialfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6686,7 +6686,7 @@ impl TryParse for GetMaterialivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6811,7 +6811,7 @@ impl TryParse for GetPixelMapfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6936,7 +6936,7 @@ impl TryParse for GetPixelMapuivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7061,7 +7061,7 @@ impl TryParse for GetPixelMapusvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7181,7 +7181,7 @@ impl TryParse for GetPolygonStippleReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -7306,7 +7306,7 @@ impl TryParse for GetStringReply { let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; let (n, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, n.try_to_usize()?)?; let string = string.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -7441,7 +7441,7 @@ impl TryParse for GetTexEnvfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7575,7 +7575,7 @@ impl TryParse for GetTexEnvivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7709,7 +7709,7 @@ impl TryParse for GetTexGendvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float64::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7843,7 +7843,7 @@ impl TryParse for GetTexGenfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7977,7 +7977,7 @@ impl TryParse for GetTexGenivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8140,7 +8140,7 @@ impl TryParse for GetTexImageReply { let (height, remaining) = i32::try_parse(remaining)?; let (depth, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -8276,7 +8276,7 @@ impl TryParse for GetTexParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8410,7 +8410,7 @@ impl TryParse for GetTexParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8553,7 +8553,7 @@ impl TryParse for GetTexLevelParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8696,7 +8696,7 @@ impl TryParse for GetTexLevelParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9062,7 +9062,7 @@ impl<'input> AreTexturesResidentRequest<'input> { } let (context_tag, remaining) = ContextTag::try_parse(value)?; let (n, remaining) = i32::try_parse(remaining)?; - let (textures, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (textures, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; let _ = remaining; Ok(AreTexturesResidentRequest { context_tag, @@ -9106,7 +9106,7 @@ impl TryParse for AreTexturesResidentReply { let (length, remaining) = u32::try_parse(remaining)?; let (ret_val, remaining) = Bool32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9198,7 +9198,7 @@ impl<'input> DeleteTexturesRequest<'input> { } let (context_tag, remaining) = ContextTag::try_parse(value)?; let (n, remaining) = i32::try_parse(remaining)?; - let (textures, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (textures, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; let _ = remaining; Ok(DeleteTexturesRequest { context_tag, @@ -9314,7 +9314,7 @@ impl TryParse for GenTexturesReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9569,7 +9569,7 @@ impl TryParse for GetColorTableReply { let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; let (width, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -9705,7 +9705,7 @@ impl TryParse for GetColorTableParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9839,7 +9839,7 @@ impl TryParse for GetColorTableParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9991,7 +9991,7 @@ impl TryParse for GetConvolutionFilterReply { let (width, remaining) = i32::try_parse(remaining)?; let (height, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -10127,7 +10127,7 @@ impl TryParse for GetConvolutionParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10261,7 +10261,7 @@ impl TryParse for GetConvolutionParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10413,7 +10413,7 @@ impl TryParse for GetSeparableFilterReply { let (row_w, remaining) = i32::try_parse(remaining)?; let (col_h, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (rows_and_cols, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (rows_and_cols, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let rows_and_cols = rows_and_cols.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -10570,7 +10570,7 @@ impl TryParse for GetHistogramReply { let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; let (width, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -10706,7 +10706,7 @@ impl TryParse for GetHistogramParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10840,7 +10840,7 @@ impl TryParse for GetHistogramParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10992,7 +10992,7 @@ impl TryParse for GetMinmaxReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -11128,7 +11128,7 @@ impl TryParse for GetMinmaxParameterfvReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = Float32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -11262,7 +11262,7 @@ impl TryParse for GetMinmaxParameterivReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -11394,7 +11394,7 @@ impl TryParse for GetCompressedTexImageARBReply { let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; let (size, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -11487,7 +11487,7 @@ impl<'input> DeleteQueriesARBRequest<'input> { } let (context_tag, remaining) = ContextTag::try_parse(value)?; let (n, remaining) = i32::try_parse(remaining)?; - let (ids, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (ids, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; let _ = remaining; Ok(DeleteQueriesARBRequest { context_tag, @@ -11603,7 +11603,7 @@ impl TryParse for GenQueriesARBReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -11842,7 +11842,7 @@ impl TryParse for GetQueryivARBReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -11976,7 +11976,7 @@ impl TryParse for GetQueryObjectivARBReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = i32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -12110,7 +12110,7 @@ impl TryParse for GetQueryObjectuivARBReply { let (n, remaining) = u32::try_parse(remaining)?; let (datum, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_list::(remaining, n.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/present.rs b/src/protocol/present.rs index 98ef7f50..ce260daf 100644 --- a/src/protocol/present.rs +++ b/src/protocol/present.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/randr.rs b/src/protocol/randr.rs index 1578f3cb..d8b1318d 100644 --- a/src/protocol/randr.rs +++ b/src/protocol/randr.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -182,7 +182,7 @@ pub struct RefreshRates { impl TryParse for RefreshRates { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (n_rates, remaining) = u16::try_parse(remaining)?; - let (rates, remaining) = crate::x11_utils::parse_list::(remaining, n_rates.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (rates, remaining) = crate::x11_utils::parse_list::(remaining, n_rates.try_to_usize()?)?; let result = RefreshRates { rates }; Ok((result, remaining)) } @@ -786,8 +786,8 @@ impl TryParse for GetScreenInfoReply { let (rate, remaining) = u16::try_parse(remaining)?; let (n_info, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (sizes, remaining) = crate::x11_utils::parse_list::(remaining, n_sizes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (rates, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(n_info).checked_sub(u32::from(n_sizes)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (sizes, remaining) = crate::x11_utils::parse_list::(remaining, n_sizes.try_to_usize()?)?; + let (rates, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(n_info).checked_sub(u32::from(n_sizes)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1297,10 +1297,10 @@ impl TryParse for GetScreenResourcesReply { let (num_modes, remaining) = u16::try_parse(remaining)?; let (names_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_to_usize()?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_to_usize()?)?; + let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_to_usize()?)?; + let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_to_usize()?)?; let names = names.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1542,10 +1542,10 @@ impl TryParse for GetOutputInfoReply { let (num_preferred, remaining) = u16::try_parse(remaining)?; let (num_clones, remaining) = u16::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; - let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (clones, remaining) = crate::x11_utils::parse_list::(remaining, num_clones.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_to_usize()?)?; + let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_to_usize()?)?; + let (clones, remaining) = crate::x11_utils::parse_list::(remaining, num_clones.try_to_usize()?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1701,7 +1701,7 @@ impl TryParse for ListOutputPropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_atoms, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1827,7 +1827,7 @@ impl TryParse for QueryOutputPropertyReply { let (range, remaining) = bool::try_parse(remaining)?; let (immutable, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?; - let (valid_values, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valid_values, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2058,7 +2058,7 @@ impl<'input> ChangeOutputPropertyRequest<'input> { let mode = mode.into(); let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (num_units, remaining) = u32::try_parse(remaining)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_units.checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_units.checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangeOutputPropertyRequest { output, @@ -2315,7 +2315,7 @@ impl TryParse for GetOutputPropertyReply { let (bytes_after, remaining) = u32::try_parse(remaining)?; let (num_items, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2803,8 +2803,8 @@ impl TryParse for GetCrtcInfoReply { let (rotations, remaining) = u16::try_parse(remaining)?; let (num_outputs, remaining) = u16::try_parse(remaining)?; let (num_possible_outputs, remaining) = u16::try_parse(remaining)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (possible, remaining) = crate::x11_utils::parse_list::(remaining, num_possible_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_to_usize()?)?; + let (possible, remaining) = crate::x11_utils::parse_list::(remaining, num_possible_outputs.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3210,9 +3210,9 @@ impl TryParse for GetCrtcGammaReply { let (length, remaining) = u32::try_parse(remaining)?; let (size, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (red, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (green, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (blue, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (red, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; + let (green, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; + let (blue, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3312,9 +3312,9 @@ impl<'input> SetCrtcGammaRequest<'input> { let (crtc, remaining) = Crtc::try_parse(value)?; let (size, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (red, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (green, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (blue, remaining) = crate::x11_utils::parse_list::(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (red, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; + let (green, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; + let (blue, remaining) = crate::x11_utils::parse_list::(remaining, size.try_to_usize()?)?; let _ = remaining; Ok(SetCrtcGammaRequest { crtc, @@ -3439,10 +3439,10 @@ impl TryParse for GetScreenResourcesCurrentReply { let (num_modes, remaining) = u16::try_parse(remaining)?; let (names_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_to_usize()?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_to_usize()?)?; + let (modes, remaining) = crate::x11_utils::parse_list::(remaining, num_modes.try_to_usize()?)?; + let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_to_usize()?)?; let names = names.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -3680,7 +3680,7 @@ impl<'input> SetCrtcTransformRequest<'input> { let (transform, remaining) = render::Transform::try_parse(remaining)?; let (filter_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, filter_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, filter_len.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -3821,20 +3821,20 @@ impl TryParse for GetCrtcTransformReply { let (pending_nparams, remaining) = u16::try_parse(remaining)?; let (current_len, remaining) = u16::try_parse(remaining)?; let (current_nparams, remaining) = u16::try_parse(remaining)?; - let (pending_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, pending_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pending_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, pending_len.try_to_usize()?)?; let pending_filter_name = pending_filter_name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (pending_params, remaining) = crate::x11_utils::parse_list::(remaining, pending_nparams.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (current_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, current_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pending_params, remaining) = crate::x11_utils::parse_list::(remaining, pending_nparams.try_to_usize()?)?; + let (current_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, current_len.try_to_usize()?)?; let current_filter_name = current_filter_name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (current_params, remaining) = crate::x11_utils::parse_list::(remaining, current_nparams.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (current_params, remaining) = crate::x11_utils::parse_list::(remaining, current_nparams.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -4471,7 +4471,7 @@ impl TryParse for GetProvidersReply { let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?; let (num_providers, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?; - let (providers, remaining) = crate::x11_utils::parse_list::(remaining, num_providers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (providers, remaining) = crate::x11_utils::parse_list::(remaining, num_providers.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -4668,11 +4668,11 @@ impl TryParse for GetProviderInfoReply { let (num_associated_providers, remaining) = u16::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (associated_providers, remaining) = crate::x11_utils::parse_list::(remaining, num_associated_providers.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (associated_capability, remaining) = crate::x11_utils::parse_list::(remaining, num_associated_providers.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_to_usize()?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_to_usize()?)?; + let (associated_providers, remaining) = crate::x11_utils::parse_list::(remaining, num_associated_providers.try_to_usize()?)?; + let (associated_capability, remaining) = crate::x11_utils::parse_list::(remaining, num_associated_providers.try_to_usize()?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -4991,7 +4991,7 @@ impl TryParse for ListProviderPropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_atoms, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5117,7 +5117,7 @@ impl TryParse for QueryProviderPropertyReply { let (range, remaining) = bool::try_parse(remaining)?; let (immutable, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?; - let (valid_values, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valid_values, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5347,7 +5347,7 @@ impl<'input> ChangeProviderPropertyRequest<'input> { let (mode, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (num_items, remaining) = u32::try_parse(remaining)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangeProviderPropertyRequest { provider, @@ -5602,7 +5602,7 @@ impl TryParse for GetProviderPropertyReply { let (bytes_after, remaining) = u32::try_parse(remaining)?; let (num_items, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -6288,7 +6288,7 @@ impl TryParse for MonitorInfo { let (height, remaining) = u16::try_parse(remaining)?; let (width_in_millimeters, remaining) = u32::try_parse(remaining)?; let (height_in_millimeters, remaining) = u32::try_parse(remaining)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, n_output.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, n_output.try_to_usize()?)?; let result = MonitorInfo { name, primary, automatic, x, y, width, height, width_in_millimeters, height_in_millimeters, outputs }; Ok((result, remaining)) } @@ -6431,7 +6431,7 @@ impl TryParse for GetMonitorsReply { let (n_monitors, remaining) = u32::try_parse(remaining)?; let (n_outputs, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (monitors, remaining) = crate::x11_utils::parse_list::(remaining, n_monitors.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (monitors, remaining) = crate::x11_utils::parse_list::(remaining, n_monitors.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -6682,8 +6682,8 @@ impl<'input> CreateLeaseRequest<'input> { let (lid, remaining) = Lease::try_parse(remaining)?; let (num_crtcs, remaining) = u16::try_parse(remaining)?; let (num_outputs, remaining) = u16::try_parse(remaining)?; - let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (crtcs, remaining) = crate::x11_utils::parse_list::(remaining, num_crtcs.try_to_usize()?)?; + let (outputs, remaining) = crate::x11_utils::parse_list::(remaining, num_outputs.try_to_usize()?)?; let _ = remaining; Ok(CreateLeaseRequest { window, diff --git a/src/protocol/record.rs b/src/protocol/record.rs index 9b7edaaa..ba12f514 100644 --- a/src/protocol/record.rs +++ b/src/protocol/record.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -371,7 +371,7 @@ impl TryParse for ClientInfo { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (client_resource, remaining) = ClientSpec::try_parse(remaining)?; let (num_ranges, remaining) = u32::try_parse(remaining)?; - let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_to_usize()?)?; let result = ClientInfo { client_resource, ranges }; Ok((result, remaining)) } @@ -595,8 +595,8 @@ impl<'input> CreateContextRequest<'input> { let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; let (num_client_specs, remaining) = u32::try_parse(remaining)?; let (num_ranges, remaining) = u32::try_parse(remaining)?; - let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_to_usize()?)?; + let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_to_usize()?)?; let _ = remaining; Ok(CreateContextRequest { context, @@ -707,8 +707,8 @@ impl<'input> RegisterClientsRequest<'input> { let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; let (num_client_specs, remaining) = u32::try_parse(remaining)?; let (num_ranges, remaining) = u32::try_parse(remaining)?; - let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_to_usize()?)?; + let (ranges, remaining) = crate::x11_utils::parse_list::(remaining, num_ranges.try_to_usize()?)?; let _ = remaining; Ok(RegisterClientsRequest { context, @@ -801,7 +801,7 @@ impl<'input> UnregisterClientsRequest<'input> { } let (context, remaining) = Context::try_parse(value)?; let (num_client_specs, remaining) = u32::try_parse(remaining)?; - let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (client_specs, remaining) = crate::x11_utils::parse_list::(remaining, num_client_specs.try_to_usize()?)?; let _ = remaining; Ok(UnregisterClientsRequest { context, @@ -914,7 +914,7 @@ impl TryParse for GetContextReply { let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; let (num_intercepted_clients, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (intercepted_clients, remaining) = crate::x11_utils::parse_list::(remaining, num_intercepted_clients.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (intercepted_clients, remaining) = crate::x11_utils::parse_list::(remaining, num_intercepted_clients.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1037,7 +1037,7 @@ impl TryParse for EnableContextReply { let (server_time, remaining) = u32::try_parse(remaining)?; let (rec_sequence_num, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); diff --git a/src/protocol/render.rs b/src/protocol/render.rs index 1f07a0ab..06a5b1dc 100644 --- a/src/protocol/render.rs +++ b/src/protocol/render.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -809,7 +809,7 @@ impl TryParse for Pictdepth { let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; let (num_visuals, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (visuals, remaining) = crate::x11_utils::parse_list::(remaining, num_visuals.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (visuals, remaining) = crate::x11_utils::parse_list::(remaining, num_visuals.try_to_usize()?)?; let result = Pictdepth { depth, visuals }; Ok((result, remaining)) } @@ -862,7 +862,7 @@ impl TryParse for Pictscreen { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (num_depths, remaining) = u32::try_parse(remaining)?; let (fallback, remaining) = Pictformat::try_parse(remaining)?; - let (depths, remaining) = crate::x11_utils::parse_list::(remaining, num_depths.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (depths, remaining) = crate::x11_utils::parse_list::(remaining, num_depths.try_to_usize()?)?; let result = Pictscreen { fallback, depths }; Ok((result, remaining)) } @@ -1495,8 +1495,8 @@ impl TryParse for QueryPictFormatsReply { let (num_visuals, remaining) = u32::try_parse(remaining)?; let (num_subpixel, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (formats, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (screens, remaining) = crate::x11_utils::parse_list::(remaining, num_screens.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (formats, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_to_usize()?)?; + let (screens, remaining) = crate::x11_utils::parse_list::(remaining, num_screens.try_to_usize()?)?; let mut remaining = remaining; let list_length = usize::try_from(num_subpixel).or(Err(ParseError::ConversionFailed))?; let mut subpixels = Vec::with_capacity(list_length); @@ -1644,7 +1644,7 @@ impl TryParse for QueryPictIndexValuesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_values, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (values, remaining) = crate::x11_utils::parse_list::(remaining, num_values.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (values, remaining) = crate::x11_utils::parse_list::(remaining, num_values.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3608,8 +3608,8 @@ impl<'input> AddGlyphsRequest<'input> { } let (glyphset, remaining) = Glyphset::try_parse(value)?; let (glyphs_len, remaining) = u32::try_parse(remaining)?; - let (glyphids, remaining) = crate::x11_utils::parse_list::(remaining, glyphs_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (glyphs, remaining) = crate::x11_utils::parse_list::(remaining, glyphs_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (glyphids, remaining) = crate::x11_utils::parse_list::(remaining, glyphs_len.try_to_usize()?)?; + let (glyphs, remaining) = crate::x11_utils::parse_list::(remaining, glyphs_len.try_to_usize()?)?; let (data, remaining) = remaining.split_at(remaining.len()); let _ = remaining; Ok(AddGlyphsRequest { @@ -4630,8 +4630,8 @@ impl TryParse for QueryFiltersReply { let (num_aliases, remaining) = u32::try_parse(remaining)?; let (num_filters, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (aliases, remaining) = crate::x11_utils::parse_list::(remaining, num_aliases.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (filters, remaining) = crate::x11_utils::parse_list::(remaining, num_filters.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (aliases, remaining) = crate::x11_utils::parse_list::(remaining, num_aliases.try_to_usize()?)?; + let (filters, remaining) = crate::x11_utils::parse_list::(remaining, num_filters.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -4740,7 +4740,7 @@ impl<'input> SetPictureFilterRequest<'input> { let (picture, remaining) = Picture::try_parse(value)?; let (filter_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (filter, remaining) = crate::x11_utils::parse_u8_list(remaining, filter_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (filter, remaining) = crate::x11_utils::parse_u8_list(remaining, filter_len.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -5286,8 +5286,8 @@ impl<'input> CreateLinearGradientRequest<'input> { let (p1, remaining) = Pointfix::try_parse(remaining)?; let (p2, remaining) = Pointfix::try_parse(remaining)?; let (num_stops, remaining) = u32::try_parse(remaining)?; - let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; + let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; let _ = remaining; Ok(CreateLinearGradientRequest { picture, @@ -5423,8 +5423,8 @@ impl<'input> CreateRadialGradientRequest<'input> { let (inner_radius, remaining) = Fixed::try_parse(remaining)?; let (outer_radius, remaining) = Fixed::try_parse(remaining)?; let (num_stops, remaining) = u32::try_parse(remaining)?; - let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; + let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; let _ = remaining; Ok(CreateRadialGradientRequest { picture, @@ -5548,8 +5548,8 @@ impl<'input> CreateConicalGradientRequest<'input> { let (center, remaining) = Pointfix::try_parse(remaining)?; let (angle, remaining) = Fixed::try_parse(remaining)?; let (num_stops, remaining) = u32::try_parse(remaining)?; - let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (stops, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; + let (colors, remaining) = crate::x11_utils::parse_list::(remaining, num_stops.try_to_usize()?)?; let _ = remaining; Ok(CreateConicalGradientRequest { picture, diff --git a/src/protocol/res.rs b/src/protocol/res.rs index a63336ac..e94b8bba 100644 --- a/src/protocol/res.rs +++ b/src/protocol/res.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -229,7 +229,7 @@ impl TryParse for ClientIdValue { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (spec, remaining) = ClientIdSpec::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; - let (value, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (value, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let result = ClientIdValue { spec, value }; Ok((result, remaining)) } @@ -385,7 +385,7 @@ impl TryParse for ResourceSizeValue { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (size, remaining) = ResourceSizeSpec::try_parse(remaining)?; let (num_cross_references, remaining) = u32::try_parse(remaining)?; - let (cross_references, remaining) = crate::x11_utils::parse_list::(remaining, num_cross_references.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (cross_references, remaining) = crate::x11_utils::parse_list::(remaining, num_cross_references.try_to_usize()?)?; let result = ResourceSizeValue { size, cross_references }; Ok((result, remaining)) } @@ -599,7 +599,7 @@ impl TryParse for QueryClientsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_clients, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (clients, remaining) = crate::x11_utils::parse_list::(remaining, num_clients.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (clients, remaining) = crate::x11_utils::parse_list::(remaining, num_clients.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -712,7 +712,7 @@ impl TryParse for QueryClientResourcesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_types, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (types, remaining) = crate::x11_utils::parse_list::(remaining, num_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (types, remaining) = crate::x11_utils::parse_list::(remaining, num_types.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -894,7 +894,7 @@ impl<'input> QueryClientIdsRequest<'input> { return Err(ParseError::InvalidValue); } let (num_specs, remaining) = u32::try_parse(value)?; - let (specs, remaining) = crate::x11_utils::parse_list::(remaining, num_specs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (specs, remaining) = crate::x11_utils::parse_list::(remaining, num_specs.try_to_usize()?)?; let _ = remaining; Ok(QueryClientIdsRequest { specs: Cow::Owned(specs), @@ -935,7 +935,7 @@ impl TryParse for QueryClientIdsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_ids, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (ids, remaining) = crate::x11_utils::parse_list::(remaining, num_ids.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (ids, remaining) = crate::x11_utils::parse_list::(remaining, num_ids.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1026,7 +1026,7 @@ impl<'input> QueryResourceBytesRequest<'input> { } let (client, remaining) = u32::try_parse(value)?; let (num_specs, remaining) = u32::try_parse(remaining)?; - let (specs, remaining) = crate::x11_utils::parse_list::(remaining, num_specs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (specs, remaining) = crate::x11_utils::parse_list::(remaining, num_specs.try_to_usize()?)?; let _ = remaining; Ok(QueryResourceBytesRequest { client, @@ -1070,7 +1070,7 @@ impl TryParse for QueryResourceBytesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_sizes, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (sizes, remaining) = crate::x11_utils::parse_list::(remaining, num_sizes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (sizes, remaining) = crate::x11_utils::parse_list::(remaining, num_sizes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/screensaver.rs b/src/protocol/screensaver.rs index 13a64472..ad0568ef 100644 --- a/src/protocol/screensaver.rs +++ b/src/protocol/screensaver.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/shape.rs b/src/protocol/shape.rs index 79246f41..a0e15905 100644 --- a/src/protocol/shape.rs +++ b/src/protocol/shape.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -1161,7 +1161,7 @@ impl TryParse for GetRectanglesReply { let (length, remaining) = u32::try_parse(remaining)?; let (rectangles_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (rectangles, remaining) = crate::x11_utils::parse_list::(remaining, rectangles_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (rectangles, remaining) = crate::x11_utils::parse_list::(remaining, rectangles_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/shm.rs b/src/protocol/shm.rs index 2f496d46..bb34a471 100644 --- a/src/protocol/shm.rs +++ b/src/protocol/shm.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/sync.rs b/src/protocol/sync.rs index 773b4125..bbf2b2c8 100644 --- a/src/protocol/sync.rs +++ b/src/protocol/sync.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -318,7 +318,7 @@ impl TryParse for Systemcounter { let (counter, remaining) = Counter::try_parse(remaining)?; let (resolution, remaining) = Int64::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -672,7 +672,7 @@ impl TryParse for ListSystemCountersReply { let (length, remaining) = u32::try_parse(remaining)?; let (counters_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (counters, remaining) = crate::x11_utils::parse_list::(remaining, counters_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (counters, remaining) = crate::x11_utils::parse_list::(remaining, counters_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xc_misc.rs b/src/protocol/xc_misc.rs index 71ce55ce..b16e4f9b 100644 --- a/src/protocol/xc_misc.rs +++ b/src/protocol/xc_misc.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -304,7 +304,7 @@ impl TryParse for GetXIDListReply { let (length, remaining) = u32::try_parse(remaining)?; let (ids_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (ids, remaining) = crate::x11_utils::parse_list::(remaining, ids_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (ids, remaining) = crate::x11_utils::parse_list::(remaining, ids_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xevie.rs b/src/protocol/xevie.rs index 2a79ce8b..fe93aea5 100644 --- a/src/protocol/xevie.rs +++ b/src/protocol/xevie.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/xf86dri.rs b/src/protocol/xf86dri.rs index 615b2962..c5143db2 100644 --- a/src/protocol/xf86dri.rs +++ b/src/protocol/xf86dri.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -353,7 +353,7 @@ impl TryParse for OpenConnectionReply { let (sarea_handle_high, remaining) = u32::try_parse(remaining)?; let (bus_id_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (bus_id, remaining) = crate::x11_utils::parse_u8_list(remaining, bus_id_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (bus_id, remaining) = crate::x11_utils::parse_u8_list(remaining, bus_id_len.try_to_usize()?)?; let bus_id = bus_id.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -538,7 +538,7 @@ impl TryParse for GetClientDriverNameReply { let (client_driver_patch_version, remaining) = u32::try_parse(remaining)?; let (client_driver_name_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (client_driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, client_driver_name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (client_driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, client_driver_name_len.try_to_usize()?)?; let client_driver_name = client_driver_name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1045,8 +1045,8 @@ impl TryParse for GetDrawableInfoReply { let (back_x, remaining) = i16::try_parse(remaining)?; let (back_y, remaining) = i16::try_parse(remaining)?; let (num_back_clip_rects, remaining) = u32::try_parse(remaining)?; - let (clip_rects, remaining) = crate::x11_utils::parse_list::(remaining, num_clip_rects.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (back_clip_rects, remaining) = crate::x11_utils::parse_list::(remaining, num_back_clip_rects.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (clip_rects, remaining) = crate::x11_utils::parse_list::(remaining, num_clip_rects.try_to_usize()?)?; + let (back_clip_rects, remaining) = crate::x11_utils::parse_list::(remaining, num_back_clip_rects.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1181,7 +1181,7 @@ impl TryParse for GetDeviceInfoReply { let (framebuffer_size, remaining) = u32::try_parse(remaining)?; let (framebuffer_stride, remaining) = u32::try_parse(remaining)?; let (device_private_size, remaining) = u32::try_parse(remaining)?; - let (device_private, remaining) = crate::x11_utils::parse_list::(remaining, device_private_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (device_private, remaining) = crate::x11_utils::parse_list::(remaining, device_private_size.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xf86vidmode.rs b/src/protocol/xf86vidmode.rs index 667ff5bb..1046414d 100644 --- a/src/protocol/xf86vidmode.rs +++ b/src/protocol/xf86vidmode.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -546,7 +546,7 @@ impl TryParse for GetModeLineReply { let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; let (privsize, remaining) = u32::try_parse(remaining)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let private = private.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -705,7 +705,7 @@ impl<'input> ModModeLineRequest<'input> { let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; let (privsize, remaining) = u32::try_parse(remaining)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let _ = remaining; Ok(ModModeLineRequest { screen, @@ -924,13 +924,13 @@ impl TryParse for GetMonitorReply { let (num_hsync, remaining) = u8::try_parse(remaining)?; let (num_vsync, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (hsync, remaining) = crate::x11_utils::parse_list::(remaining, num_hsync.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (vsync, remaining) = crate::x11_utils::parse_list::(remaining, num_vsync.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (hsync, remaining) = crate::x11_utils::parse_list::(remaining, num_hsync.try_to_usize()?)?; + let (vsync, remaining) = crate::x11_utils::parse_list::(remaining, num_vsync.try_to_usize()?)?; + let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_length.try_to_usize()?)?; let vendor = vendor.to_vec(); - let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(vendor_length).checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(vendor_length)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(vendor_length).checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(vendor_length)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let alignment_pad = alignment_pad.to_vec(); - let (model, remaining) = crate::x11_utils::parse_u8_list(remaining, model_length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (model, remaining) = crate::x11_utils::parse_u8_list(remaining, model_length.try_to_usize()?)?; let model = model.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1154,7 +1154,7 @@ impl TryParse for GetAllModeLinesReply { let (length, remaining) = u32::try_parse(remaining)?; let (modecount, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (modeinfo, remaining) = crate::x11_utils::parse_list::(remaining, modecount.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modeinfo, remaining) = crate::x11_utils::parse_list::(remaining, modecount.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1394,7 +1394,7 @@ impl<'input> AddModeLineRequest<'input> { let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (after_flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let _ = remaining; Ok(AddModeLineRequest { screen, @@ -1625,7 +1625,7 @@ impl<'input> DeleteModeLineRequest<'input> { let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; let (privsize, remaining) = u32::try_parse(remaining)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let _ = remaining; Ok(DeleteModeLineRequest { screen, @@ -1821,7 +1821,7 @@ impl<'input> ValidateModeLineRequest<'input> { let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; let (privsize, remaining) = u32::try_parse(remaining)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let _ = remaining; Ok(ValidateModeLineRequest { screen, @@ -2049,7 +2049,7 @@ impl<'input> SwitchToModeRequest<'input> { let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; let (privsize, remaining) = u32::try_parse(remaining)?; - let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?; let _ = remaining; Ok(SwitchToModeRequest { screen, @@ -2383,7 +2383,7 @@ impl TryParse for GetDotClocksReply { let (clocks, remaining) = u32::try_parse(remaining)?; let (maxclocks, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (clock, remaining) = crate::x11_utils::parse_list::(remaining, 1u32.checked_sub(flags & 1u32).ok_or(ParseError::InvalidExpression)?.checked_mul(clocks).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (clock, remaining) = crate::x11_utils::parse_list::(remaining, 1u32.checked_sub(flags & 1u32).ok_or(ParseError::InvalidExpression)?.checked_mul(clocks).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2791,9 +2791,9 @@ impl TryParse for GetGammaRampReply { let (length, remaining) = u32::try_parse(remaining)?; let (size, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (red, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; - let (green, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; - let (blue, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; + let (red, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; + let (green, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; + let (blue, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2874,9 +2874,9 @@ impl<'input> SetGammaRampRequest<'input> { } let (screen, remaining) = u16::try_parse(value)?; let (size, remaining) = u16::try_parse(remaining)?; - let (red, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; - let (green, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; - let (blue, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_into().or(Err(ParseError::ConversionFailed))?)?; + let (red, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; + let (green, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; + let (blue, remaining) = crate::x11_utils::parse_list::(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?; let _ = remaining; Ok(SetGammaRampRequest { screen, diff --git a/src/protocol/xfixes.rs b/src/protocol/xfixes.rs index 00f20b9f..72ea3943 100644 --- a/src/protocol/xfixes.rs +++ b/src/protocol/xfixes.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -1063,7 +1063,7 @@ impl TryParse for GetCursorImageReply { let (yhot, remaining) = u16::try_parse(remaining)?; let (cursor_serial, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (cursor_image, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (cursor_image, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2331,7 +2331,7 @@ impl TryParse for FetchRegionReply { let (length, remaining) = u32::try_parse(remaining)?; let (extents, remaining) = xproto::Rectangle::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (rectangles, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(2u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (rectangles, remaining) = crate::x11_utils::parse_list::(remaining, length.checked_div(2u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2704,7 +2704,7 @@ impl<'input> SetCursorNameRequest<'input> { let (cursor, remaining) = xproto::Cursor::try_parse(value)?; let (nbytes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; let _ = remaining; Ok(SetCursorNameRequest { cursor, @@ -2815,7 +2815,7 @@ impl TryParse for GetCursorNameReply { let (atom, remaining) = xproto::Atom::try_parse(remaining)?; let (nbytes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2935,8 +2935,8 @@ impl TryParse for GetCursorImageAndNameReply { let (cursor_atom, remaining) = xproto::Atom::try_parse(remaining)?; let (nbytes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (cursor_image, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (cursor_image, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(width).checked_mul(u32::from(height)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -3102,7 +3102,7 @@ impl<'input> ChangeCursorByNameRequest<'input> { let (src, remaining) = xproto::Cursor::try_parse(value)?; let (nbytes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, nbytes.try_to_usize()?)?; let _ = remaining; Ok(ChangeCursorByNameRequest { src, @@ -3521,7 +3521,7 @@ impl<'input> CreatePointerBarrierRequest<'input> { let (directions, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (num_devices, remaining) = u16::try_parse(remaining)?; - let (devices, remaining) = crate::x11_utils::parse_list::(remaining, num_devices.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (devices, remaining) = crate::x11_utils::parse_list::(remaining, num_devices.try_to_usize()?)?; let _ = remaining; Ok(CreatePointerBarrierRequest { barrier, diff --git a/src/protocol/xinerama.rs b/src/protocol/xinerama.rs index 1bcd068a..3672d3c5 100644 --- a/src/protocol/xinerama.rs +++ b/src/protocol/xinerama.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -647,7 +647,7 @@ impl TryParse for QueryScreensReply { let (length, remaining) = u32::try_parse(remaining)?; let (number, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (screen_info, remaining) = crate::x11_utils::parse_list::(remaining, number.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (screen_info, remaining) = crate::x11_utils::parse_list::(remaining, number.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xinput.rs b/src/protocol/xinput.rs index 58e24969..0e5d7b9e 100644 --- a/src/protocol/xinput.rs +++ b/src/protocol/xinput.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -137,7 +137,7 @@ impl<'input> GetExtensionVersionRequest<'input> { } let (name_len, remaining) = u16::try_parse(value)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(GetExtensionVersionRequest { name: Cow::Borrowed(name), @@ -608,7 +608,7 @@ impl TryParse for ValuatorInfo { let (axes_len, remaining) = u8::try_parse(remaining)?; let (mode, remaining) = u8::try_parse(remaining)?; let (motion_size, remaining) = u32::try_parse(remaining)?; - let (axes, remaining) = crate::x11_utils::parse_list::(remaining, axes_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (axes, remaining) = crate::x11_utils::parse_list::(remaining, axes_len.try_to_usize()?)?; let class_id = class_id.into(); let mode = mode.into(); let result = ValuatorInfo { class_id, len, mode, motion_size, axes }; @@ -742,7 +742,7 @@ impl TryParse for InputInfoInfoValuator { let (axes_len, remaining) = u8::try_parse(remaining)?; let (mode, remaining) = u8::try_parse(remaining)?; let (motion_size, remaining) = u32::try_parse(remaining)?; - let (axes, remaining) = crate::x11_utils::parse_list::(remaining, axes_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (axes, remaining) = crate::x11_utils::parse_list::(remaining, axes_len.try_to_usize()?)?; let mode = mode.into(); let result = InputInfoInfoValuator { mode, motion_size, axes }; Ok((result, remaining)) @@ -909,7 +909,7 @@ pub struct DeviceName { impl TryParse for DeviceName { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (len, remaining) = u8::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, len.try_to_usize()?)?; let string = string.to_vec(); let result = DeviceName { string }; Ok((result, remaining)) @@ -1024,9 +1024,9 @@ impl TryParse for ListInputDevicesReply { let (length, remaining) = u32::try_parse(remaining)?; let (devices_len, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (devices, remaining) = crate::x11_utils::parse_list::(remaining, devices_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (infos, remaining) = crate::x11_utils::parse_list::(remaining, devices.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(x.num_class_info)).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (names, remaining) = crate::x11_utils::parse_list::(remaining, devices_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (devices, remaining) = crate::x11_utils::parse_list::(remaining, devices_len.try_to_usize()?)?; + let (infos, remaining) = crate::x11_utils::parse_list::(remaining, devices.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(x.num_class_info)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; + let (names, remaining) = crate::x11_utils::parse_list::(remaining, devices_len.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -1185,7 +1185,7 @@ impl TryParse for OpenDeviceReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_classes, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (class_info, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (class_info, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -1453,7 +1453,7 @@ impl<'input> SelectExtensionEventRequest<'input> { let (window, remaining) = xproto::Window::try_parse(value)?; let (num_classes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(SelectExtensionEventRequest { window, @@ -1565,8 +1565,8 @@ impl TryParse for GetSelectedExtensionEventsReply { let (num_this_classes, remaining) = u16::try_parse(remaining)?; let (num_all_classes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (this_classes, remaining) = crate::x11_utils::parse_list::(remaining, num_this_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (all_classes, remaining) = crate::x11_utils::parse_list::(remaining, num_all_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (this_classes, remaining) = crate::x11_utils::parse_list::(remaining, num_this_classes.try_to_usize()?)?; + let (all_classes, remaining) = crate::x11_utils::parse_list::(remaining, num_all_classes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1733,7 +1733,7 @@ impl<'input> ChangeDeviceDontPropagateListRequest<'input> { let (mode, remaining) = u8::try_parse(remaining)?; let mode = mode.into(); let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(ChangeDeviceDontPropagateListRequest { window, @@ -1846,7 +1846,7 @@ impl TryParse for GetDeviceDontPropagateListReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_classes, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1887,7 +1887,7 @@ pub struct DeviceTimeCoord { impl DeviceTimeCoord { pub fn try_parse(remaining: &[u8], num_axes: u8) -> Result<(Self, &[u8]), ParseError> { let (time, remaining) = xproto::Timestamp::try_parse(remaining)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, num_axes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, num_axes.try_to_usize()?)?; let result = DeviceTimeCoord { time, axisvalues }; Ok((result, remaining)) } @@ -2348,7 +2348,7 @@ impl<'input> GrabDeviceRequest<'input> { let (owner_events, remaining) = bool::try_parse(remaining)?; let (device_id, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(GrabDeviceRequest { grab_window, @@ -2651,7 +2651,7 @@ impl<'input> GrabDeviceKeyRequest<'input> { let other_device_mode = other_device_mode.into(); let (owner_events, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(GrabDeviceKeyRequest { grab_window, @@ -2896,7 +2896,7 @@ impl<'input> GrabDeviceButtonRequest<'input> { let (button, remaining) = u8::try_parse(remaining)?; let (owner_events, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(GrabDeviceButtonRequest { grab_window, @@ -3737,7 +3737,7 @@ impl TryParse for StringFeedbackState { let (len, remaining) = u16::try_parse(remaining)?; let (max_symbols, remaining) = u16::try_parse(remaining)?; let (num_keysyms, remaining) = u16::try_parse(remaining)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_to_usize()?)?; let class_id = class_id.into(); let result = StringFeedbackState { class_id, feedback_id, len, max_symbols, keysyms }; Ok((result, remaining)) @@ -4070,7 +4070,7 @@ impl TryParse for FeedbackStateDataString { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (max_symbols, remaining) = u16::try_parse(remaining)?; let (num_keysyms, remaining) = u16::try_parse(remaining)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_to_usize()?)?; let result = FeedbackStateDataString { max_symbols, keysyms }; Ok((result, remaining)) } @@ -4495,7 +4495,7 @@ impl TryParse for GetFeedbackControlReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_feedbacks, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (feedbacks, remaining) = crate::x11_utils::parse_list::(remaining, num_feedbacks.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (feedbacks, remaining) = crate::x11_utils::parse_list::(remaining, num_feedbacks.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -4749,7 +4749,7 @@ impl TryParse for StringFeedbackCtl { let (len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (num_keysyms, remaining) = u16::try_parse(remaining)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_to_usize()?)?; let class_id = class_id.into(); let result = StringFeedbackCtl { class_id, feedback_id, len, keysyms }; Ok((result, remaining)) @@ -5047,7 +5047,7 @@ impl TryParse for FeedbackCtlDataString { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (num_keysyms, remaining) = u16::try_parse(remaining)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, num_keysyms.try_to_usize()?)?; let result = FeedbackCtlDataString { keysyms }; Ok((result, remaining)) } @@ -5637,7 +5637,7 @@ impl TryParse for GetDeviceKeyMappingReply { let (length, remaining) = u32::try_parse(remaining)?; let (keysyms_per_keycode, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -5731,7 +5731,7 @@ impl<'input> ChangeDeviceKeyMappingRequest<'input> { let (first_keycode, remaining) = KeyCode::try_parse(remaining)?; let (keysyms_per_keycode, remaining) = u8::try_parse(remaining)?; let (keycode_count, remaining) = u8::try_parse(remaining)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(keycode_count).checked_mul(u32::from(keysyms_per_keycode)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(keycode_count).checked_mul(u32::from(keysyms_per_keycode)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangeDeviceKeyMappingRequest { device_id, @@ -5851,7 +5851,7 @@ impl TryParse for GetDeviceModifierMappingReply { let (length, remaining) = u32::try_parse(remaining)?; let (keycodes_per_modifier, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (keymaps, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keymaps, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let keymaps = keymaps.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -5941,7 +5941,7 @@ impl<'input> SetDeviceModifierMappingRequest<'input> { let (device_id, remaining) = u8::try_parse(value)?; let (keycodes_per_modifier, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (keymaps, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keymaps, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceModifierMappingRequest { device_id, @@ -6087,7 +6087,7 @@ impl TryParse for GetDeviceButtonMappingReply { let (length, remaining) = u32::try_parse(remaining)?; let (map_size, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_size.try_to_usize()?)?; let map = map.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -6179,7 +6179,7 @@ impl<'input> SetDeviceButtonMappingRequest<'input> { let (device_id, remaining) = u8::try_parse(value)?; let (map_size, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_size.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceButtonMappingRequest { device_id, @@ -6476,7 +6476,7 @@ impl TryParse for ValuatorState { let (len, remaining) = u8::try_parse(remaining)?; let (num_valuators, remaining) = u8::try_parse(remaining)?; let (mode, remaining) = u8::try_parse(remaining)?; - let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let class_id = class_id.into(); let result = ValuatorState { class_id, len, mode, valuators }; Ok((result, remaining)) @@ -6668,7 +6668,7 @@ impl TryParse for InputStateDataValuator { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (num_valuators, remaining) = u8::try_parse(remaining)?; let (mode, remaining) = u8::try_parse(remaining)?; - let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let result = InputStateDataValuator { mode, valuators }; Ok((result, remaining)) } @@ -6908,7 +6908,7 @@ impl TryParse for QueryDeviceStateReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_classes, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -7079,7 +7079,7 @@ impl<'input> SetDeviceValuatorsRequest<'input> { let (first_valuator, remaining) = u8::try_parse(remaining)?; let (num_valuators, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuators, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceValuatorsRequest { device_id, @@ -7216,9 +7216,9 @@ impl TryParse for DeviceResolutionState { let (control_id, remaining) = u16::try_parse(remaining)?; let (len, remaining) = u16::try_parse(remaining)?; let (num_valuators, remaining) = u32::try_parse(remaining)?; - let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (resolution_min, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (resolution_max, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; + let (resolution_min, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; + let (resolution_max, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let control_id = control_id.into(); let result = DeviceResolutionState { control_id, len, resolution_values, resolution_min, resolution_max }; Ok((result, remaining)) @@ -7567,9 +7567,9 @@ pub struct DeviceStateDataResolution { impl TryParse for DeviceStateDataResolution { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (num_valuators, remaining) = u32::try_parse(remaining)?; - let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (resolution_min, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (resolution_max, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; + let (resolution_min, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; + let (resolution_max, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let result = DeviceStateDataResolution { resolution_values, resolution_min, resolution_max }; Ok((result, remaining)) } @@ -8087,7 +8087,7 @@ impl TryParse for DeviceResolutionCtl { let (first_valuator, remaining) = u8::try_parse(remaining)?; let (num_valuators, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let control_id = control_id.into(); let result = DeviceResolutionCtl { control_id, len, first_valuator, resolution_values }; Ok((result, remaining)) @@ -8431,7 +8431,7 @@ impl TryParse for DeviceCtlDataResolution { let (first_valuator, remaining) = u8::try_parse(remaining)?; let (num_valuators, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (resolution_values, remaining) = crate::x11_utils::parse_list::(remaining, num_valuators.try_to_usize()?)?; let result = DeviceCtlDataResolution { first_valuator, resolution_values }; Ok((result, remaining)) } @@ -9018,7 +9018,7 @@ impl TryParse for ListDevicePropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_atoms, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, num_atoms.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9125,7 +9125,7 @@ impl ChangeDevicePropertyAux { if switch_expr == u32::from(PropertyFormat::M8_BITS) { let remaining = outer_remaining; let value = remaining; - let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_to_usize()?)?; let data8 = data8.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -9138,7 +9138,7 @@ impl ChangeDevicePropertyAux { if switch_expr == u32::from(PropertyFormat::M16_BITS) { let remaining = outer_remaining; let value = remaining; - let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -9149,7 +9149,7 @@ impl ChangeDevicePropertyAux { } if switch_expr == u32::from(PropertyFormat::M32_BITS) { let remaining = outer_remaining; - let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; outer_remaining = remaining; assert!(parse_result.is_none(), "The XML should prevent more than one 'if' from matching"); parse_result = Some(ChangeDevicePropertyAux::Data32(data32)); @@ -9534,7 +9534,7 @@ impl GetDevicePropertyItems { if switch_expr == u32::from(PropertyFormat::M8_BITS) { let remaining = outer_remaining; let value = remaining; - let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_to_usize()?)?; let data8 = data8.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -9547,7 +9547,7 @@ impl GetDevicePropertyItems { if switch_expr == u32::from(PropertyFormat::M16_BITS) { let remaining = outer_remaining; let value = remaining; - let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -9558,7 +9558,7 @@ impl GetDevicePropertyItems { } if switch_expr == u32::from(PropertyFormat::M32_BITS) { let remaining = outer_remaining; - let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; outer_remaining = remaining; assert!(parse_result.is_none(), "The XML should prevent more than one 'if' from matching"); parse_result = Some(GetDevicePropertyItems::Data32(data32)); @@ -9916,7 +9916,7 @@ impl TryParse for XIQueryPointerReply { let (buttons_len, remaining) = u16::try_parse(remaining)?; let (mods, remaining) = ModifierInfo::try_parse(remaining)?; let (group, remaining) = GroupInfo::try_parse(remaining)?; - let (buttons, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (buttons, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10301,7 +10301,7 @@ impl TryParse for AddMaster { let (name_len, remaining) = u16::try_parse(remaining)?; let (send_core, remaining) = bool::try_parse(remaining)?; let (enable, remaining) = bool::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -10531,7 +10531,7 @@ impl TryParse for HierarchyChangeDataAddMaster { let (name_len, remaining) = u16::try_parse(remaining)?; let (send_core, remaining) = bool::try_parse(remaining)?; let (enable, remaining) = bool::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -10887,7 +10887,7 @@ impl<'input> XIChangeHierarchyRequest<'input> { } let (num_changes, remaining) = u8::try_parse(value)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; - let (changes, remaining) = crate::x11_utils::parse_list::(remaining, num_changes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (changes, remaining) = crate::x11_utils::parse_list::(remaining, num_changes.try_to_usize()?)?; let _ = remaining; Ok(XIChangeHierarchyRequest { changes: Cow::Owned(changes), @@ -11194,7 +11194,7 @@ impl TryParse for EventMask { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (deviceid, remaining) = DeviceId::try_parse(remaining)?; let (mask_len, remaining) = u16::try_parse(remaining)?; - let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_to_usize()?)?; let result = EventMask { deviceid, mask }; Ok((result, remaining)) } @@ -11295,7 +11295,7 @@ impl<'input> XISelectEventsRequest<'input> { let (window, remaining) = xproto::Window::try_parse(value)?; let (num_mask, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (masks, remaining) = crate::x11_utils::parse_list::(remaining, num_mask.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (masks, remaining) = crate::x11_utils::parse_list::(remaining, num_mask.try_to_usize()?)?; let _ = remaining; Ok(XISelectEventsRequest { window, @@ -11727,8 +11727,8 @@ impl TryParse for ButtonClass { let (len, remaining) = u16::try_parse(remaining)?; let (sourceid, remaining) = DeviceId::try_parse(remaining)?; let (num_buttons, remaining) = u16::try_parse(remaining)?; - let (state, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(num_buttons).checked_add(31u32).ok_or(ParseError::InvalidExpression)?.checked_div(32u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (labels, remaining) = crate::x11_utils::parse_list::(remaining, num_buttons.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (state, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(num_buttons).checked_add(31u32).ok_or(ParseError::InvalidExpression)?.checked_div(32u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; + let (labels, remaining) = crate::x11_utils::parse_list::(remaining, num_buttons.try_to_usize()?)?; let type_ = type_.into(); let result = ButtonClass { type_, len, sourceid, state, labels }; Ok((result, remaining)) @@ -11788,7 +11788,7 @@ impl TryParse for KeyClass { let (len, remaining) = u16::try_parse(remaining)?; let (sourceid, remaining) = DeviceId::try_parse(remaining)?; let (num_keys, remaining) = u16::try_parse(remaining)?; - let (keys, remaining) = crate::x11_utils::parse_list::(remaining, num_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keys, remaining) = crate::x11_utils::parse_list::(remaining, num_keys.try_to_usize()?)?; let type_ = type_.into(); let result = KeyClass { type_, len, sourceid, keys }; Ok((result, remaining)) @@ -12092,7 +12092,7 @@ pub struct DeviceClassDataKey { impl TryParse for DeviceClassDataKey { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (num_keys, remaining) = u16::try_parse(remaining)?; - let (keys, remaining) = crate::x11_utils::parse_list::(remaining, num_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keys, remaining) = crate::x11_utils::parse_list::(remaining, num_keys.try_to_usize()?)?; let result = DeviceClassDataKey { keys }; Ok((result, remaining)) } @@ -12139,8 +12139,8 @@ pub struct DeviceClassDataButton { impl TryParse for DeviceClassDataButton { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (num_buttons, remaining) = u16::try_parse(remaining)?; - let (state, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(num_buttons).checked_add(31u32).ok_or(ParseError::InvalidExpression)?.checked_div(32u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (labels, remaining) = crate::x11_utils::parse_list::(remaining, num_buttons.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (state, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(num_buttons).checked_add(31u32).ok_or(ParseError::InvalidExpression)?.checked_div(32u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; + let (labels, remaining) = crate::x11_utils::parse_list::(remaining, num_buttons.try_to_usize()?)?; let result = DeviceClassDataButton { state, labels }; Ok((result, remaining)) } @@ -12542,13 +12542,13 @@ impl TryParse for XIDeviceInfo { let (name_len, remaining) = u16::try_parse(remaining)?; let (enabled, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let type_ = type_.into(); let result = XIDeviceInfo { deviceid, type_, attachment, enabled, name, classes }; Ok((result, remaining)) @@ -12695,7 +12695,7 @@ impl TryParse for XIQueryDeviceReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_infos, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (infos, remaining) = crate::x11_utils::parse_list::(remaining, num_infos.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (infos, remaining) = crate::x11_utils::parse_list::(remaining, num_infos.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -13078,7 +13078,7 @@ impl<'input> XIGrabDeviceRequest<'input> { let owner_events = owner_events.into(); let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; let (mask_len, remaining) = u16::try_parse(remaining)?; - let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_to_usize()?)?; let _ = remaining; Ok(XIGrabDeviceRequest { window, @@ -13741,8 +13741,8 @@ impl<'input> XIPassiveGrabDeviceRequest<'input> { let (owner_events, remaining) = bool::try_parse(remaining)?; let owner_events = owner_events.into(); let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (mask, remaining) = crate::x11_utils::parse_list::(remaining, mask_len.try_to_usize()?)?; + let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_to_usize()?)?; let _ = remaining; Ok(XIPassiveGrabDeviceRequest { time, @@ -13817,7 +13817,7 @@ impl TryParse for XIPassiveGrabDeviceReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_modifiers, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -13927,7 +13927,7 @@ impl<'input> XIPassiveUngrabDeviceRequest<'input> { let (grab_type, remaining) = u8::try_parse(remaining)?; let grab_type = grab_type.into(); let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; - let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modifiers, remaining) = crate::x11_utils::parse_list::(remaining, num_modifiers.try_to_usize()?)?; let _ = remaining; Ok(XIPassiveUngrabDeviceRequest { grab_window, @@ -14050,7 +14050,7 @@ impl TryParse for XIListPropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_properties, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (properties, remaining) = crate::x11_utils::parse_list::(remaining, num_properties.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (properties, remaining) = crate::x11_utils::parse_list::(remaining, num_properties.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -14097,7 +14097,7 @@ impl XIChangePropertyAux { if switch_expr == u32::from(PropertyFormat::M8_BITS) { let remaining = outer_remaining; let value = remaining; - let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_to_usize()?)?; let data8 = data8.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -14110,7 +14110,7 @@ impl XIChangePropertyAux { if switch_expr == u32::from(PropertyFormat::M16_BITS) { let remaining = outer_remaining; let value = remaining; - let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -14121,7 +14121,7 @@ impl XIChangePropertyAux { } if switch_expr == u32::from(PropertyFormat::M32_BITS) { let remaining = outer_remaining; - let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; outer_remaining = remaining; assert!(parse_result.is_none(), "The XML should prevent more than one 'if' from matching"); parse_result = Some(XIChangePropertyAux::Data32(data32)); @@ -14511,7 +14511,7 @@ impl XIGetPropertyItems { if switch_expr == u32::from(PropertyFormat::M8_BITS) { let remaining = outer_remaining; let value = remaining; - let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data8, remaining) = crate::x11_utils::parse_u8_list(remaining, num_items.try_to_usize()?)?; let data8 = data8.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -14524,7 +14524,7 @@ impl XIGetPropertyItems { if switch_expr == u32::from(PropertyFormat::M16_BITS) { let remaining = outer_remaining; let value = remaining; - let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data16, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -14535,7 +14535,7 @@ impl XIGetPropertyItems { } if switch_expr == u32::from(PropertyFormat::M32_BITS) { let remaining = outer_remaining; - let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data32, remaining) = crate::x11_utils::parse_list::(remaining, num_items.try_to_usize()?)?; outer_remaining = remaining; assert!(parse_result.is_none(), "The XML should prevent more than one 'if' from matching"); parse_result = Some(XIGetPropertyItems::Data32(data32)); @@ -14686,7 +14686,7 @@ impl TryParse for XIGetSelectedEventsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_masks, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (masks, remaining) = crate::x11_utils::parse_list::(remaining, num_masks.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (masks, remaining) = crate::x11_utils::parse_list::(remaining, num_masks.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -14822,7 +14822,7 @@ impl<'input> XIBarrierReleasePointerRequest<'input> { return Err(ParseError::InvalidValue); } let (num_barriers, remaining) = u32::try_parse(value)?; - let (barriers, remaining) = crate::x11_utils::parse_list::(remaining, num_barriers.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (barriers, remaining) = crate::x11_utils::parse_list::(remaining, num_barriers.try_to_usize()?)?; let _ = remaining; Ok(XIBarrierReleasePointerRequest { barriers: Cow::Owned(barriers), @@ -16112,7 +16112,7 @@ impl TryParse for DeviceChangedEvent { let (sourceid, remaining) = DeviceId::try_parse(remaining)?; let (reason, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(11..).ok_or(ParseError::InsufficientData)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let reason = reason.into(); let result = DeviceChangedEvent { response_type, extension, sequence, length, event_type, deviceid, time, sourceid, reason, classes }; let _ = remaining; @@ -16240,9 +16240,9 @@ impl TryParse for KeyPressEvent { let (flags, remaining) = u32::try_parse(remaining)?; let (mods, remaining) = ModifierInfo::try_parse(remaining)?; let (group, remaining) = GroupInfo::try_parse(remaining)?; - let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_to_usize()?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = KeyPressEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, root, event, child, root_x, root_y, event_x, event_y, sourceid, flags, mods, group, button_mask, valuator_mask, axisvalues }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -16386,9 +16386,9 @@ impl TryParse for ButtonPressEvent { let (flags, remaining) = u32::try_parse(remaining)?; let (mods, remaining) = ModifierInfo::try_parse(remaining)?; let (group, remaining) = GroupInfo::try_parse(remaining)?; - let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_to_usize()?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = ButtonPressEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, root, event, child, root_x, root_y, event_x, event_y, sourceid, flags, mods, group, button_mask, valuator_mask, axisvalues }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -16627,7 +16627,7 @@ impl TryParse for EnterEvent { let (buttons_len, remaining) = u16::try_parse(remaining)?; let (mods, remaining) = ModifierInfo::try_parse(remaining)?; let (group, remaining) = GroupInfo::try_parse(remaining)?; - let (buttons, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (buttons, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_to_usize()?)?; let mode = mode.into(); let detail = detail.into(); let result = EnterEvent { response_type, extension, sequence, length, event_type, deviceid, time, sourceid, mode, detail, root, event, child, root_x, root_y, event_x, event_y, same_screen, focus, mods, group, buttons }; @@ -16830,7 +16830,7 @@ impl TryParse for HierarchyEvent { let (flags, remaining) = u32::try_parse(remaining)?; let (num_infos, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?; - let (infos, remaining) = crate::x11_utils::parse_list::(remaining, num_infos.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (infos, remaining) = crate::x11_utils::parse_list::(remaining, num_infos.try_to_usize()?)?; let result = HierarchyEvent { response_type, extension, sequence, length, event_type, deviceid, time, flags, infos }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -16995,9 +16995,9 @@ impl TryParse for RawKeyPressEvent { let (valuators_len, remaining) = u16::try_parse(remaining)?; let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; + let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = RawKeyPressEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, sourceid, flags, valuator_mask, axisvalues, axisvalues_raw }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -17064,9 +17064,9 @@ impl TryParse for RawButtonPressEvent { let (valuators_len, remaining) = u16::try_parse(remaining)?; let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; + let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = RawButtonPressEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, sourceid, flags, valuator_mask, axisvalues, axisvalues_raw }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -17203,9 +17203,9 @@ impl TryParse for TouchBeginEvent { let (flags, remaining) = u32::try_parse(remaining)?; let (mods, remaining) = ModifierInfo::try_parse(remaining)?; let (group, remaining) = GroupInfo::try_parse(remaining)?; - let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (button_mask, remaining) = crate::x11_utils::parse_list::(remaining, buttons_len.try_to_usize()?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = TouchBeginEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, root, event, child, root_x, root_y, event_x, event_y, sourceid, flags, mods, group, button_mask, valuator_mask, axisvalues }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -17384,9 +17384,9 @@ impl TryParse for RawTouchBeginEvent { let (valuators_len, remaining) = u16::try_parse(remaining)?; let (flags, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (valuator_mask, remaining) = crate::x11_utils::parse_list::(remaining, valuators_len.try_to_usize()?)?; + let (axisvalues, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; + let (axisvalues_raw, remaining) = crate::x11_utils::parse_list::(remaining, valuator_mask.iter().try_fold(0u32, |acc, x| acc.checked_add((*x).count_ones()).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = RawTouchBeginEvent { response_type, extension, sequence, length, event_type, deviceid, time, detail, sourceid, flags, valuator_mask, axisvalues, axisvalues_raw }; let _ = remaining; let remaining = initial_value.get(32 + length as usize * 4..) @@ -17830,8 +17830,8 @@ impl<'input> SendExtensionEventRequest<'input> { let (num_classes, remaining) = u16::try_parse(remaining)?; let (num_events, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; - let (events, remaining) = crate::x11_utils::parse_list::(remaining, num_events.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (events, remaining) = crate::x11_utils::parse_list::(remaining, num_events.try_to_usize()?)?; + let (classes, remaining) = crate::x11_utils::parse_list::(remaining, num_classes.try_to_usize()?)?; let _ = remaining; Ok(SendExtensionEventRequest { destination, diff --git a/src/protocol/xkb.rs b/src/protocol/xkb.rs index 379c8973..bc10a8f9 100644 --- a/src/protocol/xkb.rs +++ b/src/protocol/xkb.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -2441,9 +2441,9 @@ pub struct CountedString16 { impl TryParse for CountedString16 { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (length, remaining) = u16::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_to_usize()?)?; let string = string.to_vec(); - let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(length).checked_add(5u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(length).checked_add(2u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(length).checked_add(5u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(length).checked_add(2u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let alignment_pad = alignment_pad.to_vec(); let result = CountedString16 { string, alignment_pad }; Ok((result, remaining)) @@ -2561,8 +2561,8 @@ impl TryParse for KeyType { let (n_map_entries, remaining) = u8::try_parse(remaining)?; let (has_preserve, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (map, remaining) = crate::x11_utils::parse_list::(remaining, n_map_entries.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (preserve, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(has_preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (map, remaining) = crate::x11_utils::parse_list::(remaining, n_map_entries.try_to_usize()?)?; + let (preserve, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(has_preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let result = KeyType { mods_mask, mods_mods, mods_vmods, num_levels, has_preserve, map, preserve }; Ok((result, remaining)) } @@ -2625,7 +2625,7 @@ impl TryParse for KeySymMap { let (group_info, remaining) = u8::try_parse(remaining)?; let (width, remaining) = u8::try_parse(remaining)?; let (n_syms, remaining) = u16::try_parse(remaining)?; - let (syms, remaining) = crate::x11_utils::parse_list::(remaining, n_syms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (syms, remaining) = crate::x11_utils::parse_list::(remaining, n_syms.try_to_usize()?)?; let result = KeySymMap { kt_index, group_info, width, syms }; Ok((result, remaining)) } @@ -3250,8 +3250,8 @@ impl TryParse for SetKeyType { let (n_map_entries, remaining) = u8::try_parse(remaining)?; let (preserve, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (entries, remaining) = crate::x11_utils::parse_list::(remaining, n_map_entries.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (preserve_entries, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (entries, remaining) = crate::x11_utils::parse_list::(remaining, n_map_entries.try_to_usize()?)?; + let (preserve_entries, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(preserve).checked_mul(u32::from(n_map_entries)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let result = SetKeyType { mask, real_mods, virtual_mods, num_levels, preserve, entries, preserve_entries }; Ok((result, remaining)) } @@ -3312,7 +3312,7 @@ impl TryParse for Outline { let (n_points, remaining) = u8::try_parse(remaining)?; let (corner_radius, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (points, remaining) = crate::x11_utils::parse_list::(remaining, n_points.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (points, remaining) = crate::x11_utils::parse_list::(remaining, n_points.try_to_usize()?)?; let result = Outline { corner_radius, points }; Ok((result, remaining)) } @@ -3369,7 +3369,7 @@ impl TryParse for Shape { let (primary_ndx, remaining) = u8::try_parse(remaining)?; let (approx_ndx, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (outlines, remaining) = crate::x11_utils::parse_list::(remaining, n_outlines.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (outlines, remaining) = crate::x11_utils::parse_list::(remaining, n_outlines.try_to_usize()?)?; let result = Shape { name, primary_ndx, approx_ndx, outlines }; Ok((result, remaining)) } @@ -3516,7 +3516,7 @@ impl TryParse for OverlayRow { let (row_under, remaining) = u8::try_parse(remaining)?; let (n_keys, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (keys, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keys, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_to_usize()?)?; let result = OverlayRow { row_under, keys }; Ok((result, remaining)) } @@ -3569,7 +3569,7 @@ impl TryParse for Overlay { let (name, remaining) = xproto::Atom::try_parse(remaining)?; let (n_rows, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; - let (rows, remaining) = crate::x11_utils::parse_list::(remaining, n_rows.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (rows, remaining) = crate::x11_utils::parse_list::(remaining, n_rows.try_to_usize()?)?; let result = Overlay { name, rows }; Ok((result, remaining)) } @@ -3626,7 +3626,7 @@ impl TryParse for Row { let (n_keys, remaining) = u8::try_parse(remaining)?; let (vertical, remaining) = bool::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (keys, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keys, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_to_usize()?)?; let result = Row { top, left, vertical, keys }; Ok((result, remaining)) } @@ -3745,7 +3745,7 @@ impl TryParse for Listing { let value = remaining; let (flags, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u16::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, length.try_to_usize()?)?; let string = string.to_vec(); // Align offset to multiple of 2 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -3812,8 +3812,8 @@ impl TryParse for DeviceLedInfo { let (maps_present, remaining) = u32::try_parse(remaining)?; let (phys_indicators, remaining) = u32::try_parse(remaining)?; let (state, remaining) = u32::try_parse(remaining)?; - let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_present.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; - let (maps, remaining) = crate::x11_utils::parse_list::(remaining, maps_present.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_present.count_ones().try_to_usize()?)?; + let (maps, remaining) = crate::x11_utils::parse_list::(remaining, maps_present.count_ones().try_to_usize()?)?; let led_class = led_class.into(); let result = DeviceLedInfo { led_class, led_id, names_present, maps_present, phys_indicators, state, names, maps }; Ok((result, remaining)) @@ -7940,13 +7940,13 @@ pub struct GetMapMapBitcase3 { impl GetMapMapBitcase3 { pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?; let acts_rtrn_count = acts_rtrn_count.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_to_usize()?)?; let result = GetMapMapBitcase3 { acts_rtrn_count, acts_rtrn_acts }; Ok((result, remaining)) } @@ -7969,7 +7969,7 @@ impl GetMapMap { let mut outer_remaining = value; let types_rtrn = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 { let remaining = outer_remaining; - let (types_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (types_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(types_rtrn) } else { @@ -7977,7 +7977,7 @@ impl GetMapMap { }; let syms_rtrn = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 { let remaining = outer_remaining; - let (syms_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (syms_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_to_usize()?)?; outer_remaining = remaining; Some(syms_rtrn) } else { @@ -7992,7 +7992,7 @@ impl GetMapMap { }; let behaviors_rtrn = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 { let remaining = outer_remaining; - let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_to_usize()?)?; outer_remaining = remaining; Some(behaviors_rtrn) } else { @@ -8001,7 +8001,7 @@ impl GetMapMap { let vmods_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 { let remaining = outer_remaining; let value = remaining; - let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?; let vmods_rtrn = vmods_rtrn.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -8015,7 +8015,7 @@ impl GetMapMap { let explicit_rtrn = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 { let remaining = outer_remaining; let value = remaining; - let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -8028,7 +8028,7 @@ impl GetMapMap { let modmap_rtrn = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 { let remaining = outer_remaining; let value = remaining; - let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -8040,7 +8040,7 @@ impl GetMapMap { }; let vmodmap_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 { let remaining = outer_remaining; - let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_to_usize()?)?; outer_remaining = remaining; Some(vmodmap_rtrn) } else { @@ -8142,13 +8142,13 @@ pub struct SetMapAuxBitcase3 { impl SetMapAuxBitcase3 { pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (actions_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (actions_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?; let actions_count = actions_count.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (actions, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (actions, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_to_usize()?)?; let result = SetMapAuxBitcase3 { actions_count, actions }; Ok((result, remaining)) } @@ -8187,7 +8187,7 @@ impl SetMapAux { let mut outer_remaining = value; let types = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 { let remaining = outer_remaining; - let (types, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (types, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(types) } else { @@ -8195,7 +8195,7 @@ impl SetMapAux { }; let syms = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 { let remaining = outer_remaining; - let (syms, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (syms, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_to_usize()?)?; outer_remaining = remaining; Some(syms) } else { @@ -8210,7 +8210,7 @@ impl SetMapAux { }; let behaviors = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 { let remaining = outer_remaining; - let (behaviors, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (behaviors, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_to_usize()?)?; outer_remaining = remaining; Some(behaviors) } else { @@ -8219,7 +8219,7 @@ impl SetMapAux { let vmods = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 { let remaining = outer_remaining; let value = remaining; - let (vmods, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmods, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?; let vmods = vmods.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -8232,7 +8232,7 @@ impl SetMapAux { }; let explicit = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 { let remaining = outer_remaining; - let (explicit, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (explicit, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_to_usize()?)?; outer_remaining = remaining; Some(explicit) } else { @@ -8240,7 +8240,7 @@ impl SetMapAux { }; let modmap = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 { let remaining = outer_remaining; - let (modmap, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modmap, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_to_usize()?)?; outer_remaining = remaining; Some(modmap) } else { @@ -8248,7 +8248,7 @@ impl SetMapAux { }; let vmodmap = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 { let remaining = outer_remaining; - let (vmodmap, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmodmap, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_to_usize()?)?; outer_remaining = remaining; Some(vmodmap) } else { @@ -8752,8 +8752,8 @@ impl TryParse for GetCompatMapReply { let (n_si_rtrn, remaining) = u16::try_parse(remaining)?; let (n_total_si, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (si_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_si_rtrn.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (group_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, groups_rtrn.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (si_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_si_rtrn.try_to_usize()?)?; + let (group_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, groups_rtrn.count_ones().try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8866,8 +8866,8 @@ impl<'input> SetCompatMapRequest<'input> { let (first_si, remaining) = u16::try_parse(remaining)?; let (n_si, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (si, remaining) = crate::x11_utils::parse_list::(remaining, n_si.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (group_maps, remaining) = crate::x11_utils::parse_list::(remaining, groups.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (si, remaining) = crate::x11_utils::parse_list::(remaining, n_si.try_to_usize()?)?; + let (group_maps, remaining) = crate::x11_utils::parse_list::(remaining, groups.count_ones().try_to_usize()?)?; let _ = remaining; Ok(SetCompatMapRequest { device_spec, @@ -9108,7 +9108,7 @@ impl TryParse for GetIndicatorMapReply { let (real_indicators, remaining) = u32::try_parse(remaining)?; let (n_indicators, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?; - let (maps, remaining) = crate::x11_utils::parse_list::(remaining, which.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (maps, remaining) = crate::x11_utils::parse_list::(remaining, which.count_ones().try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -9186,7 +9186,7 @@ impl<'input> SetIndicatorMapRequest<'input> { let (device_spec, remaining) = DeviceSpec::try_parse(value)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (which, remaining) = u32::try_parse(remaining)?; - let (maps, remaining) = crate::x11_utils::parse_list::(remaining, which.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (maps, remaining) = crate::x11_utils::parse_list::(remaining, which.count_ones().try_to_usize()?)?; let _ = remaining; Ok(SetIndicatorMapRequest { device_spec, @@ -9632,13 +9632,13 @@ pub struct GetNamesValueListBitcase8 { impl GetNamesValueListBitcase8 { pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?; let n_levels_per_type = n_levels_per_type.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = GetNamesValueListBitcase8 { n_levels_per_type, kt_level_names }; Ok((result, remaining)) } @@ -9715,7 +9715,7 @@ impl GetNamesValueList { }; let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { let remaining = outer_remaining; - let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(type_names) } else { @@ -9730,7 +9730,7 @@ impl GetNamesValueList { }; let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { let remaining = outer_remaining; - let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(indicator_names) } else { @@ -9738,7 +9738,7 @@ impl GetNamesValueList { }; let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { let remaining = outer_remaining; - let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(virtual_mod_names) } else { @@ -9746,7 +9746,7 @@ impl GetNamesValueList { }; let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { let remaining = outer_remaining; - let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(groups) } else { @@ -9754,7 +9754,7 @@ impl GetNamesValueList { }; let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { let remaining = outer_remaining; - let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_to_usize()?)?; outer_remaining = remaining; Some(key_names) } else { @@ -9762,7 +9762,7 @@ impl GetNamesValueList { }; let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { let remaining = outer_remaining; - let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_to_usize()?)?; outer_remaining = remaining; Some(key_aliases) } else { @@ -9770,7 +9770,7 @@ impl GetNamesValueList { }; let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { let remaining = outer_remaining; - let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_to_usize()?)?; outer_remaining = remaining; Some(radio_group_names) } else { @@ -9845,13 +9845,13 @@ pub struct SetNamesAuxBitcase8 { impl SetNamesAuxBitcase8 { pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?; let n_levels_per_type = n_levels_per_type.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = SetNamesAuxBitcase8 { n_levels_per_type, kt_level_names }; Ok((result, remaining)) } @@ -9944,7 +9944,7 @@ impl SetNamesAux { }; let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { let remaining = outer_remaining; - let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(type_names) } else { @@ -9959,7 +9959,7 @@ impl SetNamesAux { }; let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { let remaining = outer_remaining; - let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(indicator_names) } else { @@ -9967,7 +9967,7 @@ impl SetNamesAux { }; let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { let remaining = outer_remaining; - let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(virtual_mod_names) } else { @@ -9975,7 +9975,7 @@ impl SetNamesAux { }; let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { let remaining = outer_remaining; - let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(groups) } else { @@ -9983,7 +9983,7 @@ impl SetNamesAux { }; let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { let remaining = outer_remaining; - let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_to_usize()?)?; outer_remaining = remaining; Some(key_names) } else { @@ -9991,7 +9991,7 @@ impl SetNamesAux { }; let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { let remaining = outer_remaining; - let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_to_usize()?)?; outer_remaining = remaining; Some(key_aliases) } else { @@ -9999,7 +9999,7 @@ impl SetNamesAux { }; let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { let remaining = outer_remaining; - let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_to_usize()?)?; outer_remaining = remaining; Some(radio_group_names) } else { @@ -10632,12 +10632,12 @@ impl TryParse for ListComponentsReply { let (n_geometries, remaining) = u16::try_parse(remaining)?; let (extra, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?; - let (keymaps, remaining) = crate::x11_utils::parse_list::(remaining, n_keymaps.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (keycodes, remaining) = crate::x11_utils::parse_list::(remaining, n_keycodes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (types, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (compat_maps, remaining) = crate::x11_utils::parse_list::(remaining, n_compat_maps.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (symbols, remaining) = crate::x11_utils::parse_list::(remaining, n_symbols.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (geometries, remaining) = crate::x11_utils::parse_list::(remaining, n_geometries.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keymaps, remaining) = crate::x11_utils::parse_list::(remaining, n_keymaps.try_to_usize()?)?; + let (keycodes, remaining) = crate::x11_utils::parse_list::(remaining, n_keycodes.try_to_usize()?)?; + let (types, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; + let (compat_maps, remaining) = crate::x11_utils::parse_list::(remaining, n_compat_maps.try_to_usize()?)?; + let (symbols, remaining) = crate::x11_utils::parse_list::(remaining, n_symbols.try_to_usize()?)?; + let (geometries, remaining) = crate::x11_utils::parse_list::(remaining, n_geometries.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -10832,13 +10832,13 @@ pub struct GetKbdByNameRepliesTypesMapBitcase3 { impl GetKbdByNameRepliesTypesMapBitcase3 { pub fn try_parse(remaining: &[u8], n_key_actions: u8, total_actions: u16) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (acts_rtrn_count, remaining) = crate::x11_utils::parse_u8_list(remaining, n_key_actions.try_to_usize()?)?; let acts_rtrn_count = acts_rtrn_count.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (acts_rtrn_acts, remaining) = crate::x11_utils::parse_list::(remaining, total_actions.try_to_usize()?)?; let result = GetKbdByNameRepliesTypesMapBitcase3 { acts_rtrn_count, acts_rtrn_acts }; Ok((result, remaining)) } @@ -10861,7 +10861,7 @@ impl GetKbdByNameRepliesTypesMap { let mut outer_remaining = value; let types_rtrn = if switch_expr & u32::from(MapPart::KEY_TYPES) != 0 { let remaining = outer_remaining; - let (types_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (types_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(types_rtrn) } else { @@ -10869,7 +10869,7 @@ impl GetKbdByNameRepliesTypesMap { }; let syms_rtrn = if switch_expr & u32::from(MapPart::KEY_SYMS) != 0 { let remaining = outer_remaining; - let (syms_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (syms_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_key_syms.try_to_usize()?)?; outer_remaining = remaining; Some(syms_rtrn) } else { @@ -10884,7 +10884,7 @@ impl GetKbdByNameRepliesTypesMap { }; let behaviors_rtrn = if switch_expr & u32::from(MapPart::KEY_BEHAVIORS) != 0 { let remaining = outer_remaining; - let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (behaviors_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_behaviors.try_to_usize()?)?; outer_remaining = remaining; Some(behaviors_rtrn) } else { @@ -10893,7 +10893,7 @@ impl GetKbdByNameRepliesTypesMap { let vmods_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MODS) != 0 { let remaining = outer_remaining; let value = remaining; - let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmods_rtrn, remaining) = crate::x11_utils::parse_u8_list(remaining, virtual_mods.count_ones().try_to_usize()?)?; let vmods_rtrn = vmods_rtrn.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -10907,7 +10907,7 @@ impl GetKbdByNameRepliesTypesMap { let explicit_rtrn = if switch_expr & u32::from(MapPart::EXPLICIT_COMPONENTS) != 0 { let remaining = outer_remaining; let value = remaining; - let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (explicit_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_key_explicit.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -10920,7 +10920,7 @@ impl GetKbdByNameRepliesTypesMap { let modmap_rtrn = if switch_expr & u32::from(MapPart::MODIFIER_MAP) != 0 { let remaining = outer_remaining; let value = remaining; - let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (modmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_mod_map_keys.try_to_usize()?)?; // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; @@ -10932,7 +10932,7 @@ impl GetKbdByNameRepliesTypesMap { }; let vmodmap_rtrn = if switch_expr & u32::from(MapPart::VIRTUAL_MOD_MAP) != 0 { let remaining = outer_remaining; - let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vmodmap_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, total_v_mod_map_keys.try_to_usize()?)?; outer_remaining = remaining; Some(vmodmap_rtrn) } else { @@ -11043,8 +11043,8 @@ impl TryParse for GetKbdByNameRepliesCompatMap { let (n_si_rtrn, remaining) = u16::try_parse(remaining)?; let (n_total_si, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (si_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_si_rtrn.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (group_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, groups_rtrn.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (si_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, n_si_rtrn.try_to_usize()?)?; + let (group_rtrn, remaining) = crate::x11_utils::parse_list::(remaining, groups_rtrn.count_ones().try_to_usize()?)?; let result = GetKbdByNameRepliesCompatMap { compatmap_type, compat_device_id, compatmap_sequence, compatmap_length, groups_rtrn, first_si_rtrn, n_total_si, si_rtrn, group_rtrn }; Ok((result, remaining)) } @@ -11090,7 +11090,7 @@ impl TryParse for GetKbdByNameRepliesIndicatorMaps { let (real_indicators, remaining) = u32::try_parse(remaining)?; let (n_indicators, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?; - let (maps, remaining) = crate::x11_utils::parse_list::(remaining, n_indicators.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (maps, remaining) = crate::x11_utils::parse_list::(remaining, n_indicators.try_to_usize()?)?; let result = GetKbdByNameRepliesIndicatorMaps { indicatormap_type, indicator_device_id, indicatormap_sequence, indicatormap_length, which, real_indicators, maps }; Ok((result, remaining)) } @@ -11124,13 +11124,13 @@ pub struct GetKbdByNameRepliesKeyNamesValueListBitcase8 { impl GetKbdByNameRepliesKeyNamesValueListBitcase8 { pub fn try_parse(remaining: &[u8], n_types: u8) -> Result<(Self, &[u8]), ParseError> { let value = remaining; - let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (n_levels_per_type, remaining) = crate::x11_utils::parse_u8_list(remaining, n_types.try_to_usize()?)?; let n_levels_per_type = n_levels_per_type.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (kt_level_names, remaining) = crate::x11_utils::parse_list::(remaining, n_levels_per_type.iter().try_fold(0u32, |acc, x| acc.checked_add(u32::from(*x)).ok_or(ParseError::InvalidExpression))?.try_to_usize()?)?; let result = GetKbdByNameRepliesKeyNamesValueListBitcase8 { n_levels_per_type, kt_level_names }; Ok((result, remaining)) } @@ -11207,7 +11207,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let type_names = if switch_expr & u32::from(NameDetail::KEY_TYPE_NAMES) != 0 { let remaining = outer_remaining; - let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (type_names, remaining) = crate::x11_utils::parse_list::(remaining, n_types.try_to_usize()?)?; outer_remaining = remaining; Some(type_names) } else { @@ -11222,7 +11222,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let indicator_names = if switch_expr & u32::from(NameDetail::INDICATOR_NAMES) != 0 { let remaining = outer_remaining; - let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (indicator_names, remaining) = crate::x11_utils::parse_list::(remaining, indicators.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(indicator_names) } else { @@ -11230,7 +11230,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let virtual_mod_names = if switch_expr & u32::from(NameDetail::VIRTUAL_MOD_NAMES) != 0 { let remaining = outer_remaining; - let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (virtual_mod_names, remaining) = crate::x11_utils::parse_list::(remaining, virtual_mods.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(virtual_mod_names) } else { @@ -11238,7 +11238,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let groups = if switch_expr & u32::from(NameDetail::GROUP_NAMES) != 0 { let remaining = outer_remaining; - let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_into().or(Err(ParseError::ConversionFailed))?)?; + let (groups, remaining) = crate::x11_utils::parse_list::(remaining, group_names.count_ones().try_to_usize()?)?; outer_remaining = remaining; Some(groups) } else { @@ -11246,7 +11246,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let key_names = if switch_expr & u32::from(NameDetail::KEY_NAMES) != 0 { let remaining = outer_remaining; - let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_names, remaining) = crate::x11_utils::parse_list::(remaining, n_keys.try_to_usize()?)?; outer_remaining = remaining; Some(key_names) } else { @@ -11254,7 +11254,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let key_aliases = if switch_expr & u32::from(NameDetail::KEY_ALIASES) != 0 { let remaining = outer_remaining; - let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (key_aliases, remaining) = crate::x11_utils::parse_list::(remaining, n_key_aliases.try_to_usize()?)?; outer_remaining = remaining; Some(key_aliases) } else { @@ -11262,7 +11262,7 @@ impl GetKbdByNameRepliesKeyNamesValueList { }; let radio_group_names = if switch_expr & u32::from(NameDetail::RG_NAMES) != 0 { let remaining = outer_remaining; - let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (radio_group_names, remaining) = crate::x11_utils::parse_list::(remaining, n_radio_groups.try_to_usize()?)?; outer_remaining = remaining; Some(radio_group_names) } else { @@ -11621,14 +11621,14 @@ impl TryParse for GetDeviceInfoReply { let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (dev_type, remaining) = xproto::Atom::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (btn_actions, remaining) = crate::x11_utils::parse_list::(remaining, n_btns_rtrn.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (leds, remaining) = crate::x11_utils::parse_list::(remaining, n_device_led_f_bs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (btn_actions, remaining) = crate::x11_utils::parse_list::(remaining, n_btns_rtrn.try_to_usize()?)?; + let (leds, remaining) = crate::x11_utils::parse_list::(remaining, n_device_led_f_bs.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -11757,8 +11757,8 @@ impl<'input> SetDeviceInfoRequest<'input> { let (n_btns, remaining) = u8::try_parse(remaining)?; let (change, remaining) = u16::try_parse(remaining)?; let (n_device_led_f_bs, remaining) = u16::try_parse(remaining)?; - let (btn_actions, remaining) = crate::x11_utils::parse_list::(remaining, n_btns.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (leds, remaining) = crate::x11_utils::parse_list::(remaining, n_device_led_f_bs.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (btn_actions, remaining) = crate::x11_utils::parse_list::(remaining, n_btns.try_to_usize()?)?; + let (leds, remaining) = crate::x11_utils::parse_list::(remaining, n_device_led_f_bs.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceInfoRequest { device_spec, @@ -11877,7 +11877,7 @@ impl<'input> SetDebuggingFlagsRequest<'input> { let (flags, remaining) = u32::try_parse(remaining)?; let (affect_ctrls, remaining) = u32::try_parse(remaining)?; let (ctrls, remaining) = u32::try_parse(remaining)?; - let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, msg_length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (message, remaining) = crate::x11_utils::parse_u8_list(remaining, msg_length.try_to_usize()?)?; let _ = remaining; Ok(SetDebuggingFlagsRequest { affect_flags, diff --git a/src/protocol/xprint.rs b/src/protocol/xprint.rs index a682ad93..091d907f 100644 --- a/src/protocol/xprint.rs +++ b/src/protocol/xprint.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -46,14 +46,14 @@ impl TryParse for Printer { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let value = remaining; let (name_len, remaining) = u32::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; let (desc_len, remaining) = u32::try_parse(remaining)?; - let (description, remaining) = crate::x11_utils::parse_u8_list(remaining, desc_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (description, remaining) = crate::x11_utils::parse_u8_list(remaining, desc_len.try_to_usize()?)?; let description = description.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -529,8 +529,8 @@ impl<'input> PrintGetPrinterListRequest<'input> { } let (printer_name_len, remaining) = u32::try_parse(value)?; let (locale_len, remaining) = u32::try_parse(remaining)?; - let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_to_usize()?)?; + let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_to_usize()?)?; let _ = remaining; Ok(PrintGetPrinterListRequest { printer_name: Cow::Borrowed(printer_name), @@ -574,7 +574,7 @@ impl TryParse for PrintGetPrinterListReply { let (length, remaining) = u32::try_parse(remaining)?; let (list_count, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (printers, remaining) = crate::x11_utils::parse_list::(remaining, list_count.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (printers, remaining) = crate::x11_utils::parse_list::(remaining, list_count.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -727,8 +727,8 @@ impl<'input> CreateContextRequest<'input> { let (context_id, remaining) = u32::try_parse(value)?; let (printer_name_len, remaining) = u32::try_parse(remaining)?; let (locale_len, remaining) = u32::try_parse(remaining)?; - let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_to_usize()?)?; + let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_to_usize()?)?; let _ = remaining; Ok(CreateContextRequest { context_id, @@ -1391,9 +1391,9 @@ impl<'input> PrintPutDocumentDataRequest<'input> { let (len_data, remaining) = u32::try_parse(remaining)?; let (len_fmt, remaining) = u16::try_parse(remaining)?; let (len_options, remaining) = u16::try_parse(remaining)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, len_data.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (doc_format, remaining) = crate::x11_utils::parse_u8_list(remaining, len_fmt.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (options, remaining) = crate::x11_utils::parse_u8_list(remaining, len_options.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, len_data.try_to_usize()?)?; + let (doc_format, remaining) = crate::x11_utils::parse_u8_list(remaining, len_fmt.try_to_usize()?)?; + let (options, remaining) = crate::x11_utils::parse_u8_list(remaining, len_options.try_to_usize()?)?; let _ = remaining; Ok(PrintPutDocumentDataRequest { drawable, @@ -1521,7 +1521,7 @@ impl TryParse for PrintGetDocumentDataReply { let (finished_flag, remaining) = u32::try_parse(remaining)?; let (data_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1948,7 +1948,7 @@ impl TryParse for PrintGetAttributesReply { let (length, remaining) = u32::try_parse(remaining)?; let (string_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (attributes, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attributes, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_to_usize()?)?; let attributes = attributes.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2047,7 +2047,7 @@ impl<'input> PrintGetOneAttributesRequest<'input> { let (name_len, remaining) = u32::try_parse(remaining)?; let (pool, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(PrintGetOneAttributesRequest { context, @@ -2094,7 +2094,7 @@ impl TryParse for PrintGetOneAttributesReply { let (length, remaining) = u32::try_parse(remaining)?; let (value_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (value, remaining) = crate::x11_utils::parse_u8_list(remaining, value_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (value, remaining) = crate::x11_utils::parse_u8_list(remaining, value_len.try_to_usize()?)?; let value = value.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2409,7 +2409,7 @@ impl TryParse for PrintQueryScreensReply { let (length, remaining) = u32::try_parse(remaining)?; let (list_count, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (roots, remaining) = crate::x11_utils::parse_list::(remaining, list_count.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (roots, remaining) = crate::x11_utils::parse_list::(remaining, list_count.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xproto.rs b/src/protocol/xproto.rs index 36253dc9..aed0d32d 100644 --- a/src/protocol/xproto.rs +++ b/src/protocol/xproto.rs @@ -22,7 +22,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -453,7 +453,7 @@ impl TryParse for Depth { let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; let (visuals_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (visuals, remaining) = crate::x11_utils::parse_list::(remaining, visuals_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (visuals, remaining) = crate::x11_utils::parse_list::(remaining, visuals_len.try_to_usize()?)?; let result = Depth { depth, visuals }; Ok((result, remaining)) } @@ -677,7 +677,7 @@ impl TryParse for Screen { let (save_unders, remaining) = bool::try_parse(remaining)?; let (root_depth, remaining) = u8::try_parse(remaining)?; let (allowed_depths_len, remaining) = u8::try_parse(remaining)?; - let (allowed_depths, remaining) = crate::x11_utils::parse_list::(remaining, allowed_depths_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (allowed_depths, remaining) = crate::x11_utils::parse_list::(remaining, allowed_depths_len.try_to_usize()?)?; let backing_stores = backing_stores.into(); let result = Screen { root, default_colormap, white_pixel, black_pixel, current_input_masks, width_in_pixels, height_in_pixels, width_in_millimeters, height_in_millimeters, min_installed_maps, max_installed_maps, root_visual, backing_stores, save_unders, root_depth, allowed_depths }; Ok((result, remaining)) @@ -752,13 +752,13 @@ impl TryParse for SetupRequest { let (authorization_protocol_name_len, remaining) = u16::try_parse(remaining)?; let (authorization_protocol_data_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (authorization_protocol_name, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (authorization_protocol_name, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_name_len.try_to_usize()?)?; let authorization_protocol_name = authorization_protocol_name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (authorization_protocol_data, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_data_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (authorization_protocol_data, remaining) = crate::x11_utils::parse_u8_list(remaining, authorization_protocol_data_len.try_to_usize()?)?; let authorization_protocol_data = authorization_protocol_data.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -842,7 +842,7 @@ impl TryParse for SetupFailed { let (protocol_major_version, remaining) = u16::try_parse(remaining)?; let (protocol_minor_version, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u16::try_parse(remaining)?; - let (reason, remaining) = crate::x11_utils::parse_u8_list(remaining, reason_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (reason, remaining) = crate::x11_utils::parse_u8_list(remaining, reason_len.try_to_usize()?)?; let reason = reason.to_vec(); let result = SetupFailed { status, protocol_major_version, protocol_minor_version, length, reason }; Ok((result, remaining)) @@ -898,7 +898,7 @@ impl TryParse for SetupAuthenticate { let (status, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(5..).ok_or(ParseError::InsufficientData)?; let (length, remaining) = u16::try_parse(remaining)?; - let (reason, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(length).checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (reason, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(length).checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let reason = reason.to_vec(); let result = SetupAuthenticate { status, reason }; Ok((result, remaining)) @@ -1046,14 +1046,14 @@ impl TryParse for Setup { let (min_keycode, remaining) = Keycode::try_parse(remaining)?; let (max_keycode, remaining) = Keycode::try_parse(remaining)?; let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?; - let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_len.try_to_usize()?)?; let vendor = vendor.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (pixmap_formats, remaining) = crate::x11_utils::parse_list::(remaining, pixmap_formats_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (roots, remaining) = crate::x11_utils::parse_list::(remaining, roots_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pixmap_formats, remaining) = crate::x11_utils::parse_list::(remaining, pixmap_formats_len.try_to_usize()?)?; + let (roots, remaining) = crate::x11_utils::parse_list::(remaining, roots_len.try_to_usize()?)?; let image_byte_order = image_byte_order.into(); let bitmap_format_bit_order = bitmap_format_bit_order.into(); let result = Setup { status, protocol_major_version, protocol_minor_version, length, release_number, resource_id_base, resource_id_mask, motion_buffer_size, maximum_request_length, image_byte_order, bitmap_format_bit_order, bitmap_format_scanline_unit, bitmap_format_scanline_pad, min_keycode, max_keycode, vendor, pixmap_formats, roots }; @@ -8794,7 +8794,7 @@ impl TryParse for QueryTreeReply { let (parent, remaining) = Window::try_parse(remaining)?; let (children_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(14..).ok_or(ParseError::InsufficientData)?; - let (children, remaining) = crate::x11_utils::parse_list::(remaining, children_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (children, remaining) = crate::x11_utils::parse_list::(remaining, children_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -8927,7 +8927,7 @@ impl<'input> InternAtomRequest<'input> { let _ = remaining; let (name_len, remaining) = u16::try_parse(value)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(InternAtomRequest { only_if_exists, @@ -9114,7 +9114,7 @@ impl TryParse for GetAtomNameReply { let (length, remaining) = u32::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -9353,7 +9353,7 @@ impl<'input> ChangePropertyRequest<'input> { let (format, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?; let (data_len, remaining) = u32::try_parse(remaining)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangePropertyRequest { mode, @@ -10019,7 +10019,7 @@ impl TryParse for GetPropertyReply { let (bytes_after, remaining) = u32::try_parse(remaining)?; let (value_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (value, remaining) = crate::x11_utils::parse_u8_list(remaining, value_len.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (value, remaining) = crate::x11_utils::parse_u8_list(remaining, value_len.checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let value = value.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -10120,7 +10120,7 @@ impl TryParse for ListPropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (atoms_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, atoms_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, atoms_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -13374,7 +13374,7 @@ impl TryParse for GetMotionEventsReply { let (length, remaining) = u32::try_parse(remaining)?; let (events_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (events, remaining) = crate::x11_utils::parse_list::(remaining, events_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (events, remaining) = crate::x11_utils::parse_list::(remaining, events_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -14202,7 +14202,7 @@ impl<'input> OpenFontRequest<'input> { let (fid, remaining) = Font::try_parse(value)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(OpenFontRequest { fid, @@ -14613,8 +14613,8 @@ impl TryParse for QueryFontReply { let (font_ascent, remaining) = i16::try_parse(remaining)?; let (font_descent, remaining) = i16::try_parse(remaining)?; let (char_infos_len, remaining) = u32::try_parse(remaining)?; - let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (char_infos, remaining) = crate::x11_utils::parse_list::(remaining, char_infos_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_to_usize()?)?; + let (char_infos, remaining) = crate::x11_utils::parse_list::(remaining, char_infos_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -14879,7 +14879,7 @@ pub struct Str { impl TryParse for Str { fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> { let (name_len, remaining) = u8::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); let result = Str { name }; Ok((result, remaining)) @@ -14988,7 +14988,7 @@ impl<'input> ListFontsRequest<'input> { let _ = remaining; let (max_names, remaining) = u16::try_parse(value)?; let (pattern_len, remaining) = u16::try_parse(remaining)?; - let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_to_usize()?)?; let _ = remaining; Ok(ListFontsRequest { max_names, @@ -15048,7 +15048,7 @@ impl TryParse for ListFontsReply { let (length, remaining) = u32::try_parse(remaining)?; let (names_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -15149,7 +15149,7 @@ impl<'input> ListFontsWithInfoRequest<'input> { let _ = remaining; let (max_names, remaining) = u16::try_parse(value)?; let (pattern_len, remaining) = u16::try_parse(remaining)?; - let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pattern, remaining) = crate::x11_utils::parse_u8_list(remaining, pattern_len.try_to_usize()?)?; let _ = remaining; Ok(ListFontsWithInfoRequest { max_names, @@ -15248,8 +15248,8 @@ impl TryParse for ListFontsWithInfoReply { let (font_ascent, remaining) = i16::try_parse(remaining)?; let (font_descent, remaining) = i16::try_parse(remaining)?; let (replies_hint, remaining) = u32::try_parse(remaining)?; - let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_to_usize()?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let name = name.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -15351,7 +15351,7 @@ impl<'input> SetFontPathRequest<'input> { let _ = remaining; let (font_qty, remaining) = u16::try_parse(value)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (font, remaining) = crate::x11_utils::parse_list::(remaining, font_qty.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (font, remaining) = crate::x11_utils::parse_list::(remaining, font_qty.try_to_usize()?)?; let _ = remaining; Ok(SetFontPathRequest { font: Cow::Owned(font), @@ -15448,7 +15448,7 @@ impl TryParse for GetFontPathReply { let (length, remaining) = u32::try_parse(remaining)?; let (path_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (path, remaining) = crate::x11_utils::parse_list::(remaining, path_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (path, remaining) = crate::x11_utils::parse_list::(remaining, path_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -17792,7 +17792,7 @@ impl<'input> SetDashesRequest<'input> { let (gc, remaining) = Gcontext::try_parse(value)?; let (dash_offset, remaining) = u16::try_parse(remaining)?; let (dashes_len, remaining) = u16::try_parse(remaining)?; - let (dashes, remaining) = crate::x11_utils::parse_u8_list(remaining, dashes_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (dashes, remaining) = crate::x11_utils::parse_u8_list(remaining, dashes_len.try_to_usize()?)?; let _ = remaining; Ok(SetDashesRequest { gc, @@ -19996,7 +19996,7 @@ impl TryParse for GetImageReply { let (length, remaining) = u32::try_parse(remaining)?; let (visual, remaining) = Visualid::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, length.checked_mul(4u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let data = data.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -20350,7 +20350,7 @@ impl<'input> ImageText8Request<'input> { let (gc, remaining) = Gcontext::try_parse(remaining)?; let (x, remaining) = i16::try_parse(remaining)?; let (y, remaining) = i16::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_to_usize()?)?; let _ = remaining; Ok(ImageText8Request { drawable, @@ -20529,7 +20529,7 @@ impl<'input> ImageText16Request<'input> { let (gc, remaining) = Gcontext::try_parse(remaining)?; let (x, remaining) = i16::try_parse(remaining)?; let (y, remaining) = i16::try_parse(remaining)?; - let (string, remaining) = crate::x11_utils::parse_list::(remaining, string_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (string, remaining) = crate::x11_utils::parse_list::(remaining, string_len.try_to_usize()?)?; let _ = remaining; Ok(ImageText16Request { drawable, @@ -21109,7 +21109,7 @@ impl TryParse for ListInstalledColormapsReply { let (length, remaining) = u32::try_parse(remaining)?; let (cmaps_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (cmaps, remaining) = crate::x11_utils::parse_list::(remaining, cmaps_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (cmaps, remaining) = crate::x11_utils::parse_list::(remaining, cmaps_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -21367,7 +21367,7 @@ impl<'input> AllocNamedColorRequest<'input> { let (cmap, remaining) = Colormap::try_parse(value)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(AllocNamedColorRequest { cmap, @@ -21541,8 +21541,8 @@ impl TryParse for AllocColorCellsReply { let (pixels_len, remaining) = u16::try_parse(remaining)?; let (masks_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (pixels, remaining) = crate::x11_utils::parse_list::(remaining, pixels_len.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (masks, remaining) = crate::x11_utils::parse_list::(remaining, masks_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pixels, remaining) = crate::x11_utils::parse_list::(remaining, pixels_len.try_to_usize()?)?; + let (masks, remaining) = crate::x11_utils::parse_list::(remaining, masks_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -21709,7 +21709,7 @@ impl TryParse for AllocColorPlanesReply { let (green_mask, remaining) = u32::try_parse(remaining)?; let (blue_mask, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?; - let (pixels, remaining) = crate::x11_utils::parse_list::(remaining, pixels_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pixels, remaining) = crate::x11_utils::parse_list::(remaining, pixels_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -22120,7 +22120,7 @@ impl<'input> StoreNamedColorRequest<'input> { let (pixel, remaining) = u32::try_parse(remaining)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(StoreNamedColorRequest { flags, @@ -22309,7 +22309,7 @@ impl TryParse for QueryColorsReply { let (length, remaining) = u32::try_parse(remaining)?; let (colors_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (colors, remaining) = crate::x11_utils::parse_list::(remaining, colors_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (colors, remaining) = crate::x11_utils::parse_list::(remaining, colors_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -22402,7 +22402,7 @@ impl<'input> LookupColorRequest<'input> { let (cmap, remaining) = Colormap::try_parse(value)?; let (name_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(LookupColorRequest { cmap, @@ -23390,7 +23390,7 @@ impl<'input> QueryExtensionRequest<'input> { let _ = remaining; let (name_len, remaining) = u16::try_parse(value)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?; let _ = remaining; Ok(QueryExtensionRequest { name: Cow::Borrowed(name), @@ -23551,7 +23551,7 @@ impl TryParse for ListExtensionsReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (names, remaining) = crate::x11_utils::parse_list::(remaining, names_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -23644,7 +23644,7 @@ impl<'input> ChangeKeyboardMappingRequest<'input> { let (first_keycode, remaining) = Keycode::try_parse(value)?; let (keysyms_per_keycode, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(keycode_count).checked_mul(u32::from(keysyms_per_keycode)).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, u32::from(keycode_count).checked_mul(u32::from(keysyms_per_keycode)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(ChangeKeyboardMappingRequest { keycode_count, @@ -23765,7 +23765,7 @@ impl TryParse for GetKeyboardMappingReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keysyms, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -25072,7 +25072,7 @@ impl<'input> ChangeHostsRequest<'input> { let family = family.into(); let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; let (address_len, remaining) = u16::try_parse(remaining)?; - let (address, remaining) = crate::x11_utils::parse_u8_list(remaining, address_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (address, remaining) = crate::x11_utils::parse_u8_list(remaining, address_len.try_to_usize()?)?; let _ = remaining; Ok(ChangeHostsRequest { mode, @@ -25115,7 +25115,7 @@ impl TryParse for Host { let (family, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; let (address_len, remaining) = u16::try_parse(remaining)?; - let (address, remaining) = crate::x11_utils::parse_u8_list(remaining, address_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (address, remaining) = crate::x11_utils::parse_u8_list(remaining, address_len.try_to_usize()?)?; let address = address.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -25237,7 +25237,7 @@ impl TryParse for ListHostsReply { let (length, remaining) = u32::try_parse(remaining)?; let (hosts_len, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (hosts, remaining) = crate::x11_utils::parse_list::(remaining, hosts_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (hosts, remaining) = crate::x11_utils::parse_list::(remaining, hosts_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -25741,7 +25741,7 @@ impl<'input> RotatePropertiesRequest<'input> { let (window, remaining) = Window::try_parse(value)?; let (atoms_len, remaining) = u16::try_parse(remaining)?; let (delta, remaining) = i16::try_parse(remaining)?; - let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, atoms_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (atoms, remaining) = crate::x11_utils::parse_list::(remaining, atoms_len.try_to_usize()?)?; let _ = remaining; Ok(RotatePropertiesRequest { window, @@ -26001,7 +26001,7 @@ impl<'input> SetPointerMappingRequest<'input> { let remaining = &[header.minor_opcode]; let (map_len, remaining) = u8::try_parse(remaining)?; let _ = remaining; - let (map, remaining) = crate::x11_utils::parse_u8_list(value, map_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (map, remaining) = crate::x11_utils::parse_u8_list(value, map_len.try_to_usize()?)?; let _ = remaining; Ok(SetPointerMappingRequest { map: Cow::Borrowed(map), @@ -26128,7 +26128,7 @@ impl TryParse for GetPointerMappingReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (map, remaining) = crate::x11_utils::parse_u8_list(remaining, map_len.try_to_usize()?)?; let map = map.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -26280,7 +26280,7 @@ impl<'input> SetModifierMappingRequest<'input> { let remaining = &[header.minor_opcode]; let (keycodes_per_modifier, remaining) = u8::try_parse(remaining)?; let _ = remaining; - let (keycodes, remaining) = crate::x11_utils::parse_u8_list(value, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keycodes, remaining) = crate::x11_utils::parse_u8_list(value, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let _ = remaining; Ok(SetModifierMappingRequest { keycodes: Cow::Borrowed(keycodes), @@ -26407,7 +26407,7 @@ impl TryParse for GetModifierMappingReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (keycodes, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (keycodes, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(keycodes_per_modifier).checked_mul(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?; let keycodes = keycodes.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); diff --git a/src/protocol/xselinux.rs b/src/protocol/xselinux.rs index 71648d29..054e8296 100644 --- a/src/protocol/xselinux.rs +++ b/src/protocol/xselinux.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -188,7 +188,7 @@ impl<'input> SetDeviceCreateContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceCreateContextRequest { context: Cow::Borrowed(context), @@ -283,7 +283,7 @@ impl TryParse for GetDeviceCreateContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -374,7 +374,7 @@ impl<'input> SetDeviceContextRequest<'input> { } let (device, remaining) = u32::try_parse(value)?; let (context_len, remaining) = u32::try_parse(remaining)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetDeviceContextRequest { device, @@ -483,7 +483,7 @@ impl TryParse for GetDeviceContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -567,7 +567,7 @@ impl<'input> SetWindowCreateContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetWindowCreateContextRequest { context: Cow::Borrowed(context), @@ -662,7 +662,7 @@ impl TryParse for GetWindowCreateContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -776,7 +776,7 @@ impl TryParse for GetWindowContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -822,13 +822,13 @@ impl TryParse for ListItem { let (name, remaining) = xproto::Atom::try_parse(remaining)?; let (object_context_len, remaining) = u32::try_parse(remaining)?; let (data_context_len, remaining) = u32::try_parse(remaining)?; - let (object_context, remaining) = crate::x11_utils::parse_u8_list(remaining, object_context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (object_context, remaining) = crate::x11_utils::parse_u8_list(remaining, object_context_len.try_to_usize()?)?; let object_context = object_context.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (data_context, remaining) = crate::x11_utils::parse_u8_list(remaining, data_context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (data_context, remaining) = crate::x11_utils::parse_u8_list(remaining, data_context_len.try_to_usize()?)?; let data_context = data_context.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -943,7 +943,7 @@ impl<'input> SetPropertyCreateContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetPropertyCreateContextRequest { context: Cow::Borrowed(context), @@ -1038,7 +1038,7 @@ impl TryParse for GetPropertyCreateContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1122,7 +1122,7 @@ impl<'input> SetPropertyUseContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetPropertyUseContextRequest { context: Cow::Borrowed(context), @@ -1217,7 +1217,7 @@ impl TryParse for GetPropertyUseContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1340,7 +1340,7 @@ impl TryParse for GetPropertyContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1463,7 +1463,7 @@ impl TryParse for GetPropertyDataContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1577,7 +1577,7 @@ impl TryParse for ListPropertiesReply { let (length, remaining) = u32::try_parse(remaining)?; let (properties_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (properties, remaining) = crate::x11_utils::parse_list::(remaining, properties_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1660,7 +1660,7 @@ impl<'input> SetSelectionCreateContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetSelectionCreateContextRequest { context: Cow::Borrowed(context), @@ -1755,7 +1755,7 @@ impl TryParse for GetSelectionCreateContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -1839,7 +1839,7 @@ impl<'input> SetSelectionUseContextRequest<'input> { return Err(ParseError::InvalidValue); } let (context_len, remaining) = u32::try_parse(value)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let _ = remaining; Ok(SetSelectionUseContextRequest { context: Cow::Borrowed(context), @@ -1934,7 +1934,7 @@ impl TryParse for GetSelectionUseContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2048,7 +2048,7 @@ impl TryParse for GetSelectionContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2162,7 +2162,7 @@ impl TryParse for GetSelectionDataContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); @@ -2265,7 +2265,7 @@ impl TryParse for ListSelectionsReply { let (length, remaining) = u32::try_parse(remaining)?; let (selections_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (selections, remaining) = crate::x11_utils::parse_list::(remaining, selections_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (selections, remaining) = crate::x11_utils::parse_list::(remaining, selections_len.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2378,7 +2378,7 @@ impl TryParse for GetClientContextReply { let (length, remaining) = u32::try_parse(remaining)?; let (context_len, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?; let context = context.to_vec(); if response_type != 1 { return Err(ParseError::InvalidValue); diff --git a/src/protocol/xtest.rs b/src/protocol/xtest.rs index e3f40677..4f79cb3e 100644 --- a/src/protocol/xtest.rs +++ b/src/protocol/xtest.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; diff --git a/src/protocol/xv.rs b/src/protocol/xv.rs index 3b53bfd1..abba3a0e 100644 --- a/src/protocol/xv.rs +++ b/src/protocol/xv.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -571,13 +571,13 @@ impl TryParse for AdaptorInfo { let (num_formats, remaining) = u16::try_parse(remaining)?; let (type_, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_size.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; let misalignment = (4 - (offset % 4)) % 4; let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?; - let (formats, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (formats, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_to_usize()?)?; let result = AdaptorInfo { base_id, num_ports, type_, name, formats }; Ok((result, remaining)) } @@ -656,7 +656,7 @@ impl TryParse for EncodingInfo { let (height, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (rate, remaining) = Rational::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_size.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -724,9 +724,9 @@ impl TryParse for Image { let (height, remaining) = u16::try_parse(remaining)?; let (data_size, remaining) = u32::try_parse(remaining)?; let (num_planes, remaining) = u32::try_parse(remaining)?; - let (pitches, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pitches, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_to_usize()?)?; + let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_to_usize()?)?; + let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_size.try_to_usize()?)?; let data = data.to_vec(); let result = Image { id, width, height, pitches, offsets, data }; Ok((result, remaining)) @@ -803,7 +803,7 @@ impl TryParse for AttributeInfo { let (min, remaining) = i32::try_parse(remaining)?; let (max, remaining) = i32::try_parse(remaining)?; let (size, remaining) = u32::try_parse(remaining)?; - let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, size.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, size.try_to_usize()?)?; let name = name.to_vec(); // Align offset to multiple of 4 let offset = remaining.as_ptr() as usize - value.as_ptr() as usize; @@ -1455,7 +1455,7 @@ impl TryParse for QueryAdaptorsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_adaptors, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (info, remaining) = crate::x11_utils::parse_list::(remaining, num_adaptors.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (info, remaining) = crate::x11_utils::parse_list::(remaining, num_adaptors.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1568,7 +1568,7 @@ impl TryParse for QueryEncodingsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_encodings, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?; - let (info, remaining) = crate::x11_utils::parse_list::(remaining, num_encodings.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (info, remaining) = crate::x11_utils::parse_list::(remaining, num_encodings.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -2970,7 +2970,7 @@ impl TryParse for QueryPortAttributesReply { let (num_attributes, remaining) = u32::try_parse(remaining)?; let (text_size, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?; - let (attributes, remaining) = crate::x11_utils::parse_list::(remaining, num_attributes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (attributes, remaining) = crate::x11_utils::parse_list::(remaining, num_attributes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3083,7 +3083,7 @@ impl TryParse for ListImageFormatsReply { let (length, remaining) = u32::try_parse(remaining)?; let (num_formats, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (format, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (format, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -3226,8 +3226,8 @@ impl TryParse for QueryImageAttributesReply { let (width, remaining) = u16::try_parse(remaining)?; let (height, remaining) = u16::try_parse(remaining)?; let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (pitches, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_into().or(Err(ParseError::ConversionFailed))?)?; - let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (pitches, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_to_usize()?)?; + let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, num_planes.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/protocol/xvmc.rs b/src/protocol/xvmc.rs index b01c7ab7..717a77ba 100644 --- a/src/protocol/xvmc.rs +++ b/src/protocol/xvmc.rs @@ -17,7 +17,7 @@ use std::io::IoSlice; #[allow(unused_imports)] use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; #[allow(unused_imports)] -use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; +use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize}; use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection}; #[allow(unused_imports)] use crate::cookie::{Cookie, CookieWithFds, VoidCookie}; @@ -294,7 +294,7 @@ impl TryParse for ListSurfaceTypesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (surfaces, remaining) = crate::x11_utils::parse_list::(remaining, num.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (surfaces, remaining) = crate::x11_utils::parse_list::(remaining, num.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -452,7 +452,7 @@ impl TryParse for CreateContextReply { let (height_actual, remaining) = u16::try_parse(remaining)?; let (flags_return, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -637,7 +637,7 @@ impl TryParse for CreateSurfaceReply { let (sequence, remaining) = u16::try_parse(remaining)?; let (length, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?; - let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -856,7 +856,7 @@ impl TryParse for CreateSubpictureReply { let (component_order, remaining) = crate::x11_utils::parse_u8_list(remaining, 4)?; let component_order = <[u8; 4]>::try_from(component_order).unwrap(); let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?; - let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (priv_data, remaining) = crate::x11_utils::parse_list::(remaining, length.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } @@ -1043,7 +1043,7 @@ impl TryParse for ListSubpictureTypesReply { let (length, remaining) = u32::try_parse(remaining)?; let (num, remaining) = u32::try_parse(remaining)?; let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?; - let (types, remaining) = crate::x11_utils::parse_list::(remaining, num.try_into().or(Err(ParseError::ConversionFailed))?)?; + let (types, remaining) = crate::x11_utils::parse_list::(remaining, num.try_to_usize()?)?; if response_type != 1 { return Err(ParseError::InvalidValue); } diff --git a/src/x11_utils.rs b/src/x11_utils.rs index cdfcd767..9e3b347b 100644 --- a/src/x11_utils.rs +++ b/src/x11_utils.rs @@ -508,6 +508,25 @@ macro_rules! bitmask_binop { }; } +/// Wrapper around TryInto that produces a ParseError. +/// +/// This trait shortens `x.try_into().or(Err(ParseError::ConversionFailed))` to `x.try_to_usize()`. +pub(crate) trait TryIntoUSize: TryInto { + /// Attempt the conversion + fn try_to_usize(self) -> Result { + self.try_into().or(Err(ParseError::ConversionFailed)) + } +} + +impl TryIntoUSize for u8 {} +impl TryIntoUSize for u16 {} +impl TryIntoUSize for u32 {} +impl TryIntoUSize for u64 {} +impl TryIntoUSize for i8 {} +impl TryIntoUSize for i16 {} +impl TryIntoUSize for i32 {} +impl TryIntoUSize for i64 {} + /// A helper macro for managing atoms /// /// If we need to use multiple atoms, one would normally write code such as From df85d2d60c7f29adf0da89df3de4e32d1d8f5f0c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Dec 2020 14:18:29 +0100 Subject: [PATCH 3/4] Use try_to_usize() in some more cases This commit deals with two / four special cases that were not dealt with in the previous commit yet. Signed-off-by: Uli Schlachter --- generator/src/generator/namespace.rs | 4 ++-- src/protocol/dri3.rs | 4 ++-- src/protocol/render.rs | 2 +- src/protocol/xinput.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/generator/src/generator/namespace.rs b/generator/src/generator/namespace.rs index 8adc3613..88a7bd03 100644 --- a/generator/src/generator/namespace.rs +++ b/generator/src/generator/namespace.rs @@ -4132,7 +4132,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> { outln!( out, "let list_length = \ - usize::try_from({}).or(Err(ParseError::ConversionFailed))?;", + {}.try_to_usize()?;", self.expr_to_str( length_expr, to_rust_variable_name, @@ -4198,7 +4198,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> { outln!( out, - "let fds_len = usize::try_from({}).or(Err(ParseError::ConversionFailed))?;", + "let fds_len = {}.try_to_usize()?;", self.expr_to_str( &fd_list_field.length_expr, to_rust_variable_name, diff --git a/src/protocol/dri3.rs b/src/protocol/dri3.rs index 23cd2a39..87a747c3 100644 --- a/src/protocol/dri3.rs +++ b/src/protocol/dri3.rs @@ -980,7 +980,7 @@ impl PixmapFromBuffersRequest { let (bpp, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?; let (modifier, remaining) = u64::try_parse(remaining)?; - let fds_len = usize::try_from(num_buffers).or(Err(ParseError::ConversionFailed))?; + let fds_len = num_buffers.try_to_usize()?; if fds.len() < fds_len { return Err(ParseError::MissingFileDescriptors) } let mut buffers = fds.split_off(fds_len); std::mem::swap(fds, &mut buffers); @@ -1127,7 +1127,7 @@ impl TryParseFd for BuffersFromPixmapReply { let remaining = remaining.get(6..).ok_or(ParseError::InsufficientData)?; let (strides, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_to_usize()?)?; let (offsets, remaining) = crate::x11_utils::parse_list::(remaining, nfd.try_to_usize()?)?; - let fds_len = usize::try_from(nfd).or(Err(ParseError::ConversionFailed))?; + let fds_len = nfd.try_to_usize()?; if fds.len() < fds_len { return Err(ParseError::MissingFileDescriptors) } let mut buffers = fds.split_off(fds_len); std::mem::swap(fds, &mut buffers); diff --git a/src/protocol/render.rs b/src/protocol/render.rs index 06a5b1dc..0760d697 100644 --- a/src/protocol/render.rs +++ b/src/protocol/render.rs @@ -1498,7 +1498,7 @@ impl TryParse for QueryPictFormatsReply { let (formats, remaining) = crate::x11_utils::parse_list::(remaining, num_formats.try_to_usize()?)?; let (screens, remaining) = crate::x11_utils::parse_list::(remaining, num_screens.try_to_usize()?)?; let mut remaining = remaining; - let list_length = usize::try_from(num_subpixel).or(Err(ParseError::ConversionFailed))?; + let list_length = num_subpixel.try_to_usize()?; let mut subpixels = Vec::with_capacity(list_length); for _ in 0..list_length { let (v, new_remaining) = u32::try_parse(remaining)?; diff --git a/src/protocol/xinput.rs b/src/protocol/xinput.rs index 0e5d7b9e..2b3ea041 100644 --- a/src/protocol/xinput.rs +++ b/src/protocol/xinput.rs @@ -2014,7 +2014,7 @@ impl TryParse for GetDeviceMotionEventsReply { let (device_mode, remaining) = u8::try_parse(remaining)?; let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?; let mut remaining = remaining; - let list_length = usize::try_from(num_events).or(Err(ParseError::ConversionFailed))?; + let list_length = num_events.try_to_usize()?; let mut events = Vec::with_capacity(list_length); for _ in 0..list_length { let (v, new_remaining) = DeviceTimeCoord::try_parse(remaining, num_axes)?; From d9c1a6f3fd9d7ae6aebdccd58b1a8a1a7ac16214 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Dec 2020 14:46:02 +0100 Subject: [PATCH 4/4] Improve docs for ParseError::InvalidValue Signed-off-by: Uli Schlachter --- src/errors.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 2f66a2fa..2e7d82e3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -62,14 +62,26 @@ pub enum ParseError { /// A value was outside of its valid range. /// - /// When parsing the value of an enumeration, not all possible integer values have a defined - /// meaning. This error occurs when an invalid value is encountered in this context. + /// There are two kinds of situations where this error can happen: /// - /// For example, `xproto` has an enumeration `Place` with possible values `OnTop` (0) and - /// `OnBottom` (1). Any value other than 0 or 1 generates an `InvalidValue` when parsing. + /// 1. The protocol was violated and a nonsensical value was found. + /// 2. The user of the API called the wrong parsing function. + /// + /// Examples for the first kind of error: + /// + /// - One of a set of values should be present (a `` in xcb-proto-speal), but none of + /// the `` matched. This can e.g. happen when parsing + /// [`x11rb::protocol::xinput::InputInfo`]. + /// - Parsing a request with a length field that is too small for the request header to fit. + /// + /// Examples for the second kind of error: + /// + /// - Parsing an X11 error with `response_type != 0`. + /// - Parsing an X11 reply with `response_type != 1`. + /// - Parsing an X11 request with the wrong value for its `minor_opcode`. InvalidValue, - /// Some file descriptors were expected, but none were received. + /// Some file descriptors were expected, but not enough were received. MissingFileDescriptors, }