https://github.com/casey/position
☞ Source position objects for Rust
https://github.com/casey/position
Last synced: about 1 year ago
JSON representation
☞ Source position objects for Rust
- Host: GitHub
- URL: https://github.com/casey/position
- Owner: casey
- License: cc0-1.0
- Created: 2019-03-28T20:51:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-29T06:51:53.000Z (over 7 years ago)
- Last Synced: 2025-05-08T00:53:33.819Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
# position
[](https://crates.io/crates/position) [](http://docs.rs/position)
`position` provides a `Position` struct, representing a source code position,
as well as a convenient `here!()` macro for creating a position corresponding
to the location where `here!()` was invoked:
```rust
use position::{here, Position};
let p: Position = here!();
assert_eq!(p.file(), "src/lib.rs");
assert_eq!(p.line(), 5);
assert_eq!(p.column(), 19);
assert_eq!(p.module_path(), "rust_out");
assert_eq!(p.to_string(), "src/lib.rs:5:19");
```
If `position` is compiled with the `location` feature, on by default, `Position`
implements `oi::Location`, so it can be used with `oi::ErrAt::err_at`:
```rust
# #[cfg(feature = "location")]
# {
use std::{io, fs::File};
use oi::ErrAt;
use position::{here, Position};
let result: oi::Result =
File::open("foo.txt").err_at(here!());
assert_eq!(
result.unwrap_err().to_string(),
"src/lib.rs:11:32: No such file or directory (os error 2)",
);
# }
```