mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
rust: add module to convert between success/-errno and io::Result
It is a common convention in QEMU to return a positive value in case of success, and a negated errno value in case of error. Unfortunately, using errno portably in Rust is a bit complicated; on Unix the errno values are supported natively by io::Error, but on Windows they are not; so, use the libc crate. This is a set of utility functions that are used by both chardev and block layer bindings. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
4cfe9edb1b
commit
8a420dd109
6 changed files with 381 additions and 0 deletions
|
@ -92,3 +92,31 @@ macro_rules! assert_field_type {
|
|||
};
|
||||
};
|
||||
}
|
||||
|
||||
/// Assert that an expression matches a pattern. This can also be
|
||||
/// useful to compare enums that do not implement `Eq`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use qemu_api::assert_match;
|
||||
/// // JoinHandle does not implement `Eq`, therefore the result
|
||||
/// // does not either.
|
||||
/// let result: Result<std::thread::JoinHandle<()>, u32> = Err(42);
|
||||
/// assert_match!(result, Err(42));
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_match {
|
||||
($a:expr, $b:pat) => {
|
||||
assert!(
|
||||
match $a {
|
||||
$b => true,
|
||||
_ => false,
|
||||
},
|
||||
"{} = {:?} does not match {}",
|
||||
stringify!($a),
|
||||
$a,
|
||||
stringify!($b)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue