Skip to content

Commit 92691a4

Browse files
committed
create and use LogError enum
1 parent 862fa63 commit 92691a4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

log/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ unsafe impl EntryType for URID<WarningClass> {
5656
}
5757
}
5858

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+
5972
/// The Log feature
6073
#[repr(transparent)]
6174
pub struct Log<'a> {
@@ -77,11 +90,11 @@ unsafe impl<'a> Feature for Log<'a> {
7790
}
7891

7992
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> {
8194
let printf = if let Some(printf) = self.internal.printf {
8295
printf
8396
} else {
84-
return Err(());
97+
return Err(LogError::NoCallback);
8598
};
8699
//checking for null terminator
87100
let mut have_null = false;
@@ -92,7 +105,7 @@ impl<'a> Log<'a> {
92105
}
93106
}
94107
if !have_null {
95-
return Err(());
108+
return Err(LogError::NoNullTerminator);
96109
}
97110

98111
let res = unsafe {
@@ -106,7 +119,7 @@ impl<'a> Log<'a> {
106119
if res > 0 {
107120
Ok(())
108121
} else {
109-
Err(())
122+
Err(LogError::PrintError)
110123
}
111124
}
112125
}

0 commit comments

Comments
 (0)