pub struct ExtensionError { /* private fields */ }Expand description
An error that can occur during DuckDB extension initialization or registration.
This type is designed for use with the ? operator inside the extension
entry point. It can be reported back to DuckDB via access.set_error.
§Construction
use quack_rs::error::ExtensionError;
// From a string literal
let e = ExtensionError::from("something went wrong");
// From a String
let msg = format!("failed: {}", 42);
let e = ExtensionError::from(msg);
// Wrapping another error
let parse_err: Result<i32, _> = "not a number".parse();
let e = parse_err.map_err(ExtensionError::from_error);Implementations§
Source§impl ExtensionError
impl ExtensionError
Sourcepub fn new(message: impl Into<String>) -> Self
pub fn new(message: impl Into<String>) -> Self
Creates a new ExtensionError with the given message.
§Example
use quack_rs::error::ExtensionError;
let err = ExtensionError::new("registration failed");
assert_eq!(err.to_string(), "registration failed");Sourcepub fn from_error<E: Error>(e: E) -> Self
pub fn from_error<E: Error>(e: E) -> Self
Wraps any std::error::Error into an ExtensionError.
§Example
use quack_rs::error::ExtensionError;
let result: Result<i32, _> = "abc".parse::<i32>();
let err = result.map_err(ExtensionError::from_error);
assert!(err.is_err());Sourcepub fn to_c_string(&self) -> CString
pub fn to_c_string(&self) -> CString
Converts this error into a CString suitable for passing to set_error.
A null byte in the message (valid in a Rust String, not in a C
string) is replaced by ?, as on every error path in this crate
(message_to_c_string), so the
text after it is not lost.
§Example
use quack_rs::error::ExtensionError;
let err = ExtensionError::new("oops");
assert_eq!(err.to_c_string().to_str().unwrap(), "oops");
let err = ExtensionError::new("a\0b");
assert_eq!(err.to_c_string().to_str().unwrap(), "a?b");Trait Implementations§
Source§impl Clone for ExtensionError
impl Clone for ExtensionError
Source§impl Debug for ExtensionError
impl Debug for ExtensionError
Source§impl Display for ExtensionError
impl Display for ExtensionError
impl Eq for ExtensionError
Source§impl Error for ExtensionError
impl Error for ExtensionError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<&str> for ExtensionError
impl From<&str> for ExtensionError
Source§impl From<Error> for ExtensionError
impl From<Error> for ExtensionError
Source§impl From<Error> for ExtensionError
impl From<Error> for ExtensionError
Source§impl From<ErrorData> for ExtensionError
impl From<ErrorData> for ExtensionError
Source§impl From<NulError> for ExtensionError
impl From<NulError> for ExtensionError
Source§impl From<String> for ExtensionError
impl From<String> for ExtensionError
Source§impl PartialEq for ExtensionError
impl PartialEq for ExtensionError
impl StructuralPartialEq for ExtensionError
Auto Trait Implementations§
impl Freeze for ExtensionError
impl RefUnwindSafe for ExtensionError
impl Send for ExtensionError
impl Sync for ExtensionError
impl Unpin for ExtensionError
impl UnsafeUnpin for ExtensionError
impl UnwindSafe for ExtensionError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more