Re: [PATCH 1/2] libguestfs: Rust binding build error and warning fixes
Fixed break in Rust bindings where callback registering expected a *const i8, but were provided with a *const c_char. Changed to be both *const c_char in alignment with the libguestfs documentation. Signed-off-by: Jacob Reger <regerjacob@gmail.com> --- rust/src/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/event.rs b/rust/src/event.rs index 72afd3cf6..156968a69 100644 --- a/rust/src/event.rs +++ b/rust/src/event.rs @@ -29,7 +29,7 @@ type GuestfsEventCallback = extern "C" fn( u64, i32, i32, - *const i8, + *const c_char, usize, *const u64, usize, -- 2.39.5 (Apple Git-154)
Signed-off-by: Jacob Reger <regerjacob@gmail.com> --- rust/src/error.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/rust/src/error.rs b/rust/src/error.rs index ce444e199..f3709516c 100644 --- a/rust/src/error.rs +++ b/rust/src/error.rs @@ -46,6 +46,42 @@ pub enum Error { Create, } +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::API(err) => { + write!( + f, + "API Error:\n\tOperation: {}\n\tMessage: {}\n\tError Number: {}", + err.operation, err.message, err.errno + ) + } + Error::IllegalString(err) => { + write!( + f, + "Illegal string Error:\nNull byte found\n\tDetails: {}", + err + ) + } + Error::Utf8Error(err) => { + write!( + f, + "Utf8 Error:\nFailed to interpret string as utf-8\n\tDetails: {}", + err + ) + } + Error::UnixError(err, op) => { + write!(f, "Unix Error:\n\tError: {}\n\tOperation: {}", err, op) + } + Error::Create => { + write!(f, "Creation Error:\nFailed to create a guestfs handle") + } + } + } +} + +impl std::error::Error for Error {} + impl convert::From<ffi::NulError> for Error { fn from(error: ffi::NulError) -> Self { Error::IllegalString(error) -- 2.39.5 (Apple Git-154)
Internal error type did not implement the necessary traits to be treated as a proper Rust error. This would cause ergonomic issues with manual error handling and with error handling crates like anyhow. Implement the Display and Error trait for internal Error type. This also fixes the build warnings. Signed-off-by: Jacob Reger <regerjacob@gmail.com> --- rust/src/error.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/rust/src/error.rs b/rust/src/error.rs index ce444e199..f3709516c 100644 --- a/rust/src/error.rs +++ b/rust/src/error.rs @@ -46,6 +46,42 @@ pub enum Error { Create, } +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::API(err) => { + write!( + f, + "API Error:\n\tOperation: {}\n\tMessage: {}\n\tError Number: {}", + err.operation, err.message, err.errno + ) + } + Error::IllegalString(err) => { + write!( + f, + "Illegal string Error:\nNull byte found\n\tDetails: {}", + err + ) + } + Error::Utf8Error(err) => { + write!( + f, + "Utf8 Error:\nFailed to interpret string as utf-8\n\tDetails: {}", + err + ) + } + Error::UnixError(err, op) => { + write!(f, "Unix Error:\n\tError: {}\n\tOperation: {}", err, op) + } + Error::Create => { + write!(f, "Creation Error:\nFailed to create a guestfs handle") + } + } + } +} + +impl std::error::Error for Error {} + impl convert::From<ffi::NulError> for Error { fn from(error: ffi::NulError) -> Self { Error::IllegalString(error) -- 2.39.5 (Apple Git-154)
Thanks, I have pushed .. something .. in commits d7d5264ce8240fdbb712c110580b28b4913e38d2 & f81444ccadae161ef11c8e64520d1467da08f58e. Unfortunately a combination of the Apple MUA you're using and the new mailing list software we have to use seems to doubly corrupt patches. So what I pushed, while it compiles, might not be exactly what you posted. This is all unfortunate, and it may be better to use a github pull request next time. Please let me know if what's pushed isn't correct. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
participants (2)
-
Jacob Reger -
Richard W.M. Jones