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?
- Regex example to match multiline string in Rust?
- How to parse a file with Rust regex?
- How to use regex lookahead in Rust?
- How to use regex captures in Rust?
- How to use regex to match a group in Rust?
- How to match the end of a line in a Rust regex?
- How to perform matrix operations in Rust?
- How to use regex to match a double quote in Rust?
- How to replace strings using Rust regex?
See more codes...