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
- Regex example to match multiline string in Rust?
- How to use regex captures in Rust?
- How to use binary regex in Rust?
- How to print a Rust HashMap?
- How to use regex to match a double quote in 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 a URL with a regex in Rust?
- How to use regex with bytes in Rust?
- How to make regex case insensitive in Rust?
See more codes...