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 use an enum in a Rust HashMap?
- How to get a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to split a string with Rust regex?
- How to use regex lookbehind in Rust?
- How to use regex to match a double quote in Rust?
- How to get an entry from a HashSet in Rust?
- How to use regex captures in Rust?
- How to perform matrix operations in Rust?
See more codes...