-
Notifications
You must be signed in to change notification settings - Fork 604
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
The following test will not compile, since windows::Error does not implement the std::error::Error trait:
#[cfg(test)]
mod tests {
use super::*;
fn system_call() -> std::result::Result<(), std::ffi::NulError> {
Ok(())
}
fn windows_call() -> windows::Result<()> {
Err(Error::new(ErrorCode(777), "real bad..."))
}
fn can_fail() -> std::result::Result<(), Box<dyn std::error::Error>> {
let win_error = windows_call()?;
let std_error = system_call()?;
Ok(())
}
#[test]
fn can_mix_window_errors_with_std_errors() {
assert!(can_fail().is_err());
}
}
By having windows::Error implement the std::error::Error trait, the code above will compile which allows you to mix different kinds of errors in the same function. Something like this would work:
impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.message())
}
}
Is there another way to make working with different kinds of errors's easier when working with the windows crate?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request