From 2c3ff2906c624ba42d14384b324e3cabfe229f5f Mon Sep 17 00:00:00 2001 From: Hendrik Wolff Date: Sun, 29 Oct 2023 16:36:21 +0100 Subject: [PATCH 1/3] client: Include advertised version in `BindError::UnsupportVersion` --- wayland-client/src/globals.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wayland-client/src/globals.rs b/wayland-client/src/globals.rs index dc897a3edfc..76c6ad46a32 100644 --- a/wayland-client/src/globals.rs +++ b/wayland-client/src/globals.rs @@ -168,7 +168,7 @@ impl GlobalList { // Test version requirements if version < version_start { - return Err(BindError::UnsupportedVersion); + return Err(BindError::UnsupportedVersion(version)); } // To get the version to bind, take the lower of the version advertised by the server and the maximum @@ -232,7 +232,7 @@ impl From for GlobalError { #[derive(Debug)] pub enum BindError { /// The requested version of the global is not supported. - UnsupportedVersion, + UnsupportedVersion(u32), /// The requested global was not found in the registry. NotPresent, @@ -243,8 +243,8 @@ impl std::error::Error for BindError {} impl fmt::Display for BindError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - BindError::UnsupportedVersion {} => { - write!(f, "the requested version of the global is not supported") + BindError::UnsupportedVersion(version) => { + write!(f, "the available version {version} of the global is lower than the requested version") } BindError::NotPresent {} => { write!(f, "the requested global was not found in the registry") From aee3654a95920f3db47dd2c117a0cfa4a8635e3e Mon Sep 17 00:00:00 2001 From: Hendrik Wolff Date: Sun, 29 Oct 2023 16:40:38 +0100 Subject: [PATCH 2/3] client: Reduce `filter_map` + `next` to `find_map` --- wayland-client/src/globals.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wayland-client/src/globals.rs b/wayland-client/src/globals.rs index 76c6ad46a32..dbae4bbfa57 100644 --- a/wayland-client/src/globals.rs +++ b/wayland-client/src/globals.rs @@ -155,7 +155,7 @@ impl GlobalList { let (name, version) = guard .iter() // Find the with the correct interface - .filter_map(|Global { name, interface: interface_name, version }| { + .find_map(|Global { name, interface: interface_name, version }| { // TODO: then_some if interface.name == &interface_name[..] { Some((*name, *version)) @@ -163,7 +163,6 @@ impl GlobalList { None } }) - .next() .ok_or(BindError::NotPresent)?; // Test version requirements From 078ebd7783fedc34e9ec437f358560b69bd0bee6 Mon Sep 17 00:00:00 2001 From: Hendrik Wolff Date: Sun, 29 Oct 2023 16:42:23 +0100 Subject: [PATCH 3/3] client: Replace if-else with `then_some` --- wayland-client/src/globals.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/wayland-client/src/globals.rs b/wayland-client/src/globals.rs index dbae4bbfa57..4054d62111e 100644 --- a/wayland-client/src/globals.rs +++ b/wayland-client/src/globals.rs @@ -156,12 +156,7 @@ impl GlobalList { .iter() // Find the with the correct interface .find_map(|Global { name, interface: interface_name, version }| { - // TODO: then_some - if interface.name == &interface_name[..] { - Some((*name, *version)) - } else { - None - } + (interface.name == &interface_name[..]).then_some((*name, *version)) }) .ok_or(BindError::NotPresent)?;