1414
1515use std:: { fmt:: Display , num:: NonZeroUsize } ;
1616
17- use zenoh_core:: zerror;
18-
1917use super :: chunk:: AllocatedChunk ;
2018use 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+
215222impl 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]
238236pub type BufLayoutAllocResult = Result < ZShmMut , ZLayoutAllocError > ;
0 commit comments