rustHow to get error line number in Rust
Rust provides a macro called line!
which can be used to get the line number of the code.
Example code:
fn main() {
println!("This is line number {}", line!());
}
Output
This is line number 2
Explanation:
line!()
: This macro returns the line number of the code.println!
: This macro is used to print the output to the console.
Helpful links:
More of Rust
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to match whitespace with a regex in Rust?
- How to use regex captures in Rust?
- How to use regex lookbehind in Rust?
- How to use regex to match a double quote in Rust?
- How to create a HashMap of structs in Rust?
- Generator example in Rust
- How to convert the keys of a Rust HashMap to a vector?
- How to use non-capturing groups in Rust regex?
See more codes...