#line #caller #called #was #obtain

caller_line

Get the line from which the current function was called

3 releases (stable)

2.0.1 Jul 4, 2024
1.0.1 Jul 3, 2024
0.0.1 Jul 3, 2024

#4 in #caller

Download history 132/week @ 2024-06-27 208/week @ 2024-07-04 3/week @ 2024-07-11

68 downloads per month

MIT/Apache

7KB

This crate lets you obtain the line from which the current function was called.

Example

use caller_line::caller_line;

fn call_this_function() {
    let caller_line = caller_line();

    println!("called from {caller_line}");
}

fn function_wrapper() {
    call_this_function();
}

fn main() {
    function_wrapper();
}

The above code will return the following:

called from <project path>/src/main.rs:10

...where <project path> is a placeholder for the project path, and 10 is the line number of call_this_function(); in the function body of fn function_wrapper() {...}.

Dependencies

~2.4–3.5MB
~71K SLoC