Skip to content

Commit eea81bf

Browse files
authored
add missing error implementations for shared memory (#2134)
1 parent c5af8c6 commit eea81bf

File tree

1 file changed

+23
-25
lines changed
  • commons/zenoh-shm/src/api/provider

1 file changed

+23
-25
lines changed

commons/zenoh-shm/src/api/provider/types.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
use std::{fmt::Display, num::NonZeroUsize};
1616

17-
use zenoh_core::zerror;
18-
1917
use super::chunk::AllocatedChunk;
2018
use crate::api::buffer::{typed::Typed, zshmmut::ZShmMut};
2119

@@ -31,23 +29,21 @@ pub enum ZAllocError {
3129
Other,
3230
}
3331

34-
impl From<zenoh_result::Error> for ZAllocError {
35-
fn from(_value: zenoh_result::Error) -> Self {
36-
Self::Other
32+
impl Display for ZAllocError {
33+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34+
match self {
35+
ZAllocError::NeedDefragment => write!(f, "need defragmentation"),
36+
ZAllocError::OutOfMemory => write!(f, "out of memory"),
37+
ZAllocError::Other => write!(f, "other"),
38+
}
3739
}
3840
}
3941

40-
impl From<ZAllocError> for zenoh_result::Error {
41-
fn from(value: ZAllocError) -> Self {
42-
zerror!(
43-
"Allocation error: {}",
44-
match value {
45-
ZAllocError::NeedDefragment => "need defragmentation",
46-
ZAllocError::OutOfMemory => "out of memory",
47-
ZAllocError::Other => "other",
48-
}
49-
)
50-
.into()
42+
impl std::error::Error for ZAllocError {}
43+
44+
impl From<zenoh_result::Error> for ZAllocError {
45+
fn from(_value: zenoh_result::Error) -> Self {
46+
Self::Other
5147
}
5248
}
5349

@@ -212,6 +208,17 @@ pub enum ZLayoutAllocError {
212208
Layout(ZLayoutError),
213209
}
214210

211+
impl Display for ZLayoutAllocError {
212+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213+
match self {
214+
ZLayoutAllocError::Alloc(err) => write!(f, "{}", err),
215+
ZLayoutAllocError::Layout(err) => write!(f, "{}", err),
216+
}
217+
}
218+
}
219+
220+
impl std::error::Error for ZLayoutAllocError {}
221+
215222
impl From<ZLayoutError> for ZLayoutAllocError {
216223
fn from(value: ZLayoutError) -> Self {
217224
Self::Layout(value)
@@ -224,15 +231,6 @@ impl From<ZAllocError> for ZLayoutAllocError {
224231
}
225232
}
226233

227-
impl From<ZLayoutAllocError> for zenoh_result::Error {
228-
fn from(value: ZLayoutAllocError) -> Self {
229-
match value {
230-
ZLayoutAllocError::Alloc(alloc) => alloc.into(),
231-
ZLayoutAllocError::Layout(layout) => layout.into(),
232-
}
233-
}
234-
}
235-
236234
/// SHM buffer layouting and allocation result
237235
#[zenoh_macros::unstable_doc]
238236
pub type BufLayoutAllocResult = Result<ZShmMut, ZLayoutAllocError>;

0 commit comments

Comments
 (0)