@@ -56,6 +56,19 @@ unsafe impl EntryType for URID<WarningClass> {
56
56
}
57
57
}
58
58
59
+ /// Errors potentially generated by [`Log`](struct.Log.html) methods
60
+ #[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
61
+ pub enum LogError {
62
+ /// An error occured when sending message to the host
63
+ PrintError ,
64
+ /// The provided string don't have a `'\0'` to indicate it's end
65
+ NoNullTerminator ,
66
+ /// No callback was provided by the host
67
+ ///
68
+ /// This can only happen with a faulty host
69
+ NoCallback ,
70
+ }
71
+
59
72
/// The Log feature
60
73
#[ repr( transparent) ]
61
74
pub struct Log < ' a > {
@@ -77,11 +90,11 @@ unsafe impl<'a> Feature for Log<'a> {
77
90
}
78
91
79
92
impl < ' a > Log < ' a > {
80
- pub fn print ( & self , entry_type : impl EntryType , message : & str ) -> Result < ( ) , ( ) > {
93
+ pub fn print ( & self , entry_type : impl EntryType , message : & str ) -> Result < ( ) , LogError > {
81
94
let printf = if let Some ( printf) = self . internal . printf {
82
95
printf
83
96
} else {
84
- return Err ( ( ) ) ;
97
+ return Err ( LogError :: NoCallback ) ;
85
98
} ;
86
99
//checking for null terminator
87
100
let mut have_null = false ;
@@ -92,7 +105,7 @@ impl<'a> Log<'a> {
92
105
}
93
106
}
94
107
if !have_null {
95
- return Err ( ( ) ) ;
108
+ return Err ( LogError :: NoNullTerminator ) ;
96
109
}
97
110
98
111
let res = unsafe {
@@ -106,7 +119,7 @@ impl<'a> Log<'a> {
106
119
if res > 0 {
107
120
Ok ( ( ) )
108
121
} else {
109
- Err ( ( ) )
122
+ Err ( LogError :: PrintError )
110
123
}
111
124
}
112
125
}
0 commit comments