pub struct Location {
pub file: &'static str,
pub line: u32,
pub column: u32,
/* private fields */
}
Expand description
The source code location where the error was reported.
To use it, add a field location: Location
to your error. This
will automatically register it as implicitly generated
data.
§Limitations
§Rust 1.46
You need to enable the rust_1_46
feature flag for
implicit location capture. If you cannot enable that, you can
still use the location!
macro at the expense of more typing.
§Disabled context selectors
If you have disabled the context selector, SNAFU will not be able to capture an accurate location.
As a workaround, re-enable the context selector.
§Asynchronous code
When using SNAFU’s
TryFutureExt
or
TryStreamExt
extension traits, the automatically captured location will
correspond to where the future or stream was polled, not where
it was created. Additionally, many Future
or Stream
combinators do not forward the caller’s location to their
closures, causing the recorded location to be inside of the future
combinator’s library.
There are two workarounds:
// Non-ideal: will report where `wrapped_error_future` is `.await`ed.
let wrapped_error_future = error_future.context(ImplicitLocationSnafu);
// Better: will report the location of `.context`.
let wrapped_error_future = async { error_future.await.context(ImplicitLocationSnafu) };
// Better: Will report the location of `location!`
let wrapped_error_future = error_future.with_context(|_| ExplicitLocationSnafu {
location: location!(),
});
#[derive(Debug, Snafu)]
struct ImplicitLocationError {
source: AnotherError,
location: Location,
}
#[derive(Debug, Snafu)]
struct ExplicitLocationError {
source: AnotherError,
#[snafu(implicit(false))]
location: Location,
}
Fields§
§file: &'static str
The file where the error was reported
line: u32
The line where the error was reported
column: u32
The column where the error was reported
Implementations§
Trait Implementations§
source§impl GenerateImplicitData for Location
impl GenerateImplicitData for Location
impl Copy for Location
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnwindSafe for Location
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)