pub struct ErrorLocation {
pub file: &'static str,
pub line: u32,
pub column: u32,
}Expand description
A lightweight wrapper around std::panic::Location for tracking error origins.
This struct captures the file, line, and column information of where an error
was created. It’s designed to be used with the #[track_caller] attribute.
§Examples
ⓘ
use error_location::ErrorLocation;
use std::panic::Location;
#[track_caller]
fn create_error() -> ErrorLocation {
ErrorLocation::from(Location::caller())
}
let location = create_error();
println!("Error occurred at: {}", location);Fields§
§file: &'static strThe file path where the error occurred
line: u32The line number where the error occurred
column: u32The column number where the error occurred
Implementations§
Source§impl ErrorLocation
impl ErrorLocation
Sourcepub const fn from(location: &'static PanicLocation<'static>) -> Self
pub const fn from(location: &'static PanicLocation<'static>) -> Self
Creates an ErrorLocation from a std::panic::Location.
This method is designed to be used with Location::caller() in functions
marked with #[track_caller].
§Examples
ⓘ
use error_location::ErrorLocation;
use std::panic::Location;
#[track_caller]
fn get_location() -> ErrorLocation {
ErrorLocation::from(Location::caller())
}Trait Implementations§
Source§impl Clone for ErrorLocation
impl Clone for ErrorLocation
Source§fn clone(&self) -> ErrorLocation
fn clone(&self) -> ErrorLocation
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ErrorLocation
impl Debug for ErrorLocation
Source§impl Display for ErrorLocation
impl Display for ErrorLocation
impl Copy for ErrorLocation
Auto Trait Implementations§
impl Freeze for ErrorLocation
impl RefUnwindSafe for ErrorLocation
impl Send for ErrorLocation
impl Sync for ErrorLocation
impl Unpin for ErrorLocation
impl UnwindSafe for ErrorLocation
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