Function file_from_location

Source
pub fn file_from_location<'a>(loc: &'a Location<'a>) -> &'a CStr
Expand description

Gets the C string file name of a Location.

If file_with_nul() is not available, returns a string that warns about it.

ยงExamples


#[track_caller]
fn foo() {
    let caller = core::panic::Location::caller();

    // Output:
    // - A path like "rust/kernel/example.rs" if file_with_nul() is available.
    // - "<Location::file_with_nul() not supported>" otherwise.
    let caller_file = file_from_location(caller);

    // Prints out the message with caller's file name.
    pr_info!("foo() called in file {caller_file:?}\n");

}