diff --git a/commons/zenoh-keyexpr/src/key_expr/format/mod.rs b/commons/zenoh-keyexpr/src/key_expr/format/mod.rs index 8417e37ea..99cb460c8 100644 --- a/commons/zenoh-keyexpr/src/key_expr/format/mod.rs +++ b/commons/zenoh-keyexpr/src/key_expr/format/mod.rs @@ -372,7 +372,7 @@ impl<'s, Storage: IKeFormatStorage<'s>> core::fmt::Debug for KeFormatter<'s, Sto let sharp = if id.contains('}') || pattern.contains('}') || value.map_or_else( - || spec.default().map_or(false, |v| v.contains('}')), + || spec.default().is_some_and(|v| v.contains('}')), |v| v.contains('}'), ) { "#" diff --git a/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs b/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs index a6329cdf7..d63d978c6 100644 --- a/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs +++ b/commons/zenoh-keyexpr/src/key_expr/format/parsing.rs @@ -221,7 +221,7 @@ fn do_parse<'a>( } } pattern.is_double_wild() - && prefix.map_or(false, |prefix| prefix.intersects(target)) + && prefix.is_some_and(|prefix| prefix.intersects(target)) && do_parse(None, segments, results) } _ => unreachable!(), diff --git a/commons/zenoh-protocol/src/core/endpoint.rs b/commons/zenoh-protocol/src/core/endpoint.rs index 081463eb4..c1b32f33a 100644 --- a/commons/zenoh-protocol/src/core/endpoint.rs +++ b/commons/zenoh-protocol/src/core/endpoint.rs @@ -490,7 +490,7 @@ impl EndPoint { let m: &str = metadata.as_ref(); let c: &str = config.as_ref(); - let len = p.as_bytes().len() + a.as_bytes().len() + m.as_bytes().len(); + let len = p.len() + a.len() + m.len(); if len > u8::MAX as usize { bail!("Endpoint too big: {} bytes. Max: {} bytes. ", len, u8::MAX); } diff --git a/commons/zenoh-shm/src/api/provider/shm_provider.rs b/commons/zenoh-shm/src/api/provider/shm_provider.rs index 5a3af8eb9..c517529df 100644 --- a/commons/zenoh-shm/src/api/provider/shm_provider.rs +++ b/commons/zenoh-shm/src/api/provider/shm_provider.rs @@ -320,7 +320,7 @@ where provider: &ShmProvider, ) -> ChunkAllocResult { let result = InnerPolicy::alloc(layout, provider); - if let Err(ZAllocError::OutOfMemory) = result { + if result.is_err() { // try to alloc again only if GC managed to reclaim big enough chunk if provider.garbage_collect() >= layout.size().get() { return AltPolicy::alloc(layout, provider); diff --git a/commons/zenoh-shm/src/posix_shm/segment_lock.rs b/commons/zenoh-shm/src/posix_shm/segment_lock.rs index 06bd73261..ea5fcdd49 100644 --- a/commons/zenoh-shm/src/posix_shm/segment_lock.rs +++ b/commons/zenoh-shm/src/posix_shm/segment_lock.rs @@ -27,7 +27,7 @@ pub(crate) mod unix { impl Drop for ShmLock { fn drop(&mut self) { - if self.0._tempfile.try_lock(FileLockMode::Exclusive).is_ok() { + if AdvisoryFileLock::try_lock(&self.0._tempfile, FileLockMode::Exclusive).is_ok() { let _ = std::fs::remove_file(self.0.path.clone()); } } @@ -48,7 +48,7 @@ pub(crate) mod unix { .open(path.clone())?; // lock tempfile with shared lock to indicate that file is managed - tempfile.try_lock(FileLockMode::Shared)?; + AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Shared)?; Ok(Self(LockInner { path, @@ -67,7 +67,7 @@ pub(crate) mod unix { let tempfile = OpenOptions::new().read(true).open(path.clone())?; // lock tempfile with shared lock to indicate that file is managed - tempfile.try_lock(FileLockMode::Shared)?; + AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Shared)?; Ok(Self(LockInner { path, @@ -95,7 +95,7 @@ pub(crate) mod unix { .open(path.clone())?; // lock tempfile with exclusive lock to guarantee that the file is unmanaged - tempfile.try_lock(FileLockMode::Exclusive)?; + AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Exclusive)?; Ok(Self(LockInner { path, @@ -114,7 +114,7 @@ pub(crate) mod unix { type Error = (); fn try_from(value: ShmLock) -> Result { - if value.0._tempfile.try_lock(FileLockMode::Exclusive).is_ok() { + if AdvisoryFileLock::try_lock(&value.0._tempfile, FileLockMode::Exclusive).is_ok() { return Ok(unsafe { core::mem::transmute::(value) }); } Err(()) diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index fb1900b1d..cbc8955cc 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -67,8 +67,8 @@ async fn main() -> zenoh::Result<()> { // We reserve a small space at the beginning of the buffer to include the iteration index // of the write. This is simply to have the same format as zn_pub. let prefix = format!("[{idx:4}] "); - let prefix_len = prefix.as_bytes().len(); - let slice_len = prefix_len + payload.as_bytes().len(); + let prefix_len = prefix.len(); + let slice_len = prefix_len + payload.len(); sbuf[0..prefix_len].copy_from_slice(prefix.as_bytes()); sbuf[prefix_len..slice_len].copy_from_slice(payload.as_bytes()); diff --git a/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs b/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs index 3f99adc0d..de2288abd 100644 --- a/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs +++ b/io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs @@ -177,7 +177,7 @@ impl PipeR { .open(path)?; #[cfg(not(target_os = "macos"))] - read.try_lock(FileLockMode::Exclusive)?; + AdvisoryFileLock::try_lock(&read, FileLockMode::Exclusive)?; Ok(read) } } @@ -228,8 +228,8 @@ impl PipeW { let write = open_write(path)?; // the file must be already locked at the other side... #[cfg(not(target_os = "macos"))] - if write.try_lock(FileLockMode::Exclusive).is_ok() { - let _ = write.unlock(); + if AdvisoryFileLock::try_lock(&write, FileLockMode::Exclusive).is_ok() { + let _ = AdvisoryFileLock::unlock(&write); bail!("no listener...") } Ok(write) diff --git a/plugins/zenoh-plugin-trait/Cargo.toml b/plugins/zenoh-plugin-trait/Cargo.toml index 7635dd82e..12e18040e 100644 --- a/plugins/zenoh-plugin-trait/Cargo.toml +++ b/plugins/zenoh-plugin-trait/Cargo.toml @@ -23,6 +23,9 @@ license = { workspace = true } categories = { workspace = true } description = { workspace = true } +[features] +default = [] + [lib] name = "zenoh_plugin_trait" diff --git a/zenoh/src/api/session.rs b/zenoh/src/api/session.rs index 5a5785c20..fc1d12816 100644 --- a/zenoh/src/api/session.rs +++ b/zenoh/src/api/session.rs @@ -1916,13 +1916,13 @@ impl SessionInner { MatchingStatusType::Queryables(false) => state.queryables.values().any(|q| { state .local_wireexpr_to_expr(&q.key_expr) - .map_or(false, |ke| ke.intersects(key_expr)) + .is_ok_and(|ke| ke.intersects(key_expr)) }), MatchingStatusType::Queryables(true) => state.queryables.values().any(|q| { q.complete && state .local_wireexpr_to_expr(&q.key_expr) - .map_or(false, |ke| ke.includes(key_expr)) + .is_ok_and(|ke| ke.includes(key_expr)) }), }; MatchingStatus { matching } diff --git a/zenoh/src/net/routing/hat/client/queries.rs b/zenoh/src/net/routing/hat/client/queries.rs index 5c5c9c905..a7b07f407 100644 --- a/zenoh/src/net/routing/hat/client/queries.rs +++ b/zenoh/src/net/routing/hat/client/queries.rs @@ -468,7 +468,7 @@ impl HatQueriesTrait for HatCode { qbl.session_ctxs .get(&face.id) .and_then(|sc| sc.qabl) - .map_or(false, |q| q.complete) + .is_some_and(|q| q.complete) && KeyExpr::keyexpr_include(qbl.expr(), key_expr) } false => KeyExpr::keyexpr_intersect(qbl.expr(), key_expr), @@ -493,7 +493,7 @@ impl HatQueriesTrait for HatCode { for (sid, context) in &mres.session_ctxs { if context.face.whatami == WhatAmI::Client && match complete { - true => context.qabl.map_or(false, |q| q.complete), + true => context.qabl.is_some_and(|q| q.complete), false => context.qabl.is_some(), } { diff --git a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs index 6e286a52a..c122d369b 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/queries.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/queries.rs @@ -1074,7 +1074,7 @@ impl HatQueriesTrait for HatCode { for (sid, context) in &mres.session_ctxs { if match complete { - true => context.qabl.map_or(false, |q| q.complete), + true => context.qabl.is_some_and(|q| q.complete), false => context.qabl.is_some(), } { matching_queryables diff --git a/zenoh/src/net/routing/hat/p2p_peer/queries.rs b/zenoh/src/net/routing/hat/p2p_peer/queries.rs index 0791e6c65..664822f6f 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/queries.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/queries.rs @@ -719,7 +719,7 @@ impl HatQueriesTrait for HatCode { } for (sid, context) in &mres.session_ctxs { if match complete { - true => context.qabl.map_or(false, |q| q.complete), + true => context.qabl.is_some_and(|q| q.complete), false => context.qabl.is_some(), } { matching_queryables diff --git a/zenoh/src/net/routing/hat/router/queries.rs b/zenoh/src/net/routing/hat/router/queries.rs index 9896b691b..97a772a9d 100644 --- a/zenoh/src/net/routing/hat/router/queries.rs +++ b/zenoh/src/net/routing/hat/router/queries.rs @@ -1575,7 +1575,7 @@ impl HatQueriesTrait for HatCode { if master { for (sid, context) in &mres.session_ctxs { if match complete { - true => context.qabl.map_or(false, |q| q.complete), + true => context.qabl.is_some_and(|q| q.complete), false => context.qabl.is_some(), } && context.face.whatami != WhatAmI::Router {