-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macro use full name as default (#171)
* rename path_name to full_name Signed-off-by: Andy Lok <[email protected]> * default to full name Signed-off-by: Andy Lok <[email protected]> * add some useful macros Signed-off-by: Andy Lok <[email protected]> * fix Signed-off-by: Andy Lok <[email protected]> * fix Signed-off-by: Andy Lok <[email protected]> * fix Signed-off-by: Andy Lok <[email protected]> --------- Signed-off-by: Andy Lok <[email protected]>
- Loading branch information
1 parent
baafd33
commit f57f8b9
Showing
10 changed files
with
124 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ro/tests/ui/err/has-name-and-path-name.rs → ...o/tests/ui/err/has-name-and-short-name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use minitrace::trace; | ||
|
||
#[trace(name = "Name", path_name = true)] | ||
#[trace(name = "Name", short_name = true)] | ||
fn f() {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: `name` and `short_name` can not be used together | ||
--> tests/ui/err/has-name-and-short-name.rs:3:1 | ||
| | ||
3 | #[trace(name = "Name", short_name = true)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the attribute macro `trace` (in Nightly builds, run with -Z macro-backtrace for more info) |
2 changes: 1 addition & 1 deletion
2
...cro/tests/ui/ok/has-name-and-path-name.rs → ...ro/tests/ui/ok/has-name-and-short-name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
minitrace-macro/tests/ui/ok/has-path-name.rs → ...trace-macro/tests/ui/ok/has-short-name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use minitrace::trace; | ||
|
||
#[trace(path_name = true)] | ||
#[trace(short_name = true)] | ||
async fn f(a: u32) -> u32 { | ||
a | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
/// Get the name of the function where the macro is invoked. Returns a `&'static str`. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use minitrace::func_name; | ||
/// | ||
/// fn foo() { | ||
/// assert_eq!(func_name!(), "foo"); | ||
/// } | ||
/// # foo() | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! func_name { | ||
() => {{ | ||
fn f() {} | ||
fn type_name_of<T>(_: T) -> &'static str { | ||
std::any::type_name::<T>() | ||
} | ||
let name = type_name_of(f); | ||
let name = &name[..name.len() - 3]; | ||
name.rsplit("::") | ||
.find(|name| *name != "{{closure}}") | ||
.unwrap() | ||
}}; | ||
} | ||
|
||
/// Get the full path of the function where the macro is invoked. Returns a `&'static str`. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use minitrace::full_name; | ||
/// | ||
/// fn foo() { | ||
/// assert_eq!(full_name!(), "rust_out::main::_doctest_main_minitrace_src_macros_rs_34_0::foo"); | ||
/// } | ||
/// # foo() | ||
#[macro_export] | ||
macro_rules! full_name { | ||
() => {{ | ||
fn f() {} | ||
fn type_name_of<T>(_: T) -> &'static str { | ||
std::any::type_name::<T>() | ||
} | ||
let name = type_name_of(f); | ||
let name = &name[..name.len() - 3]; | ||
name.trim_end_matches("::{{closure}}") | ||
}}; | ||
} | ||
|
||
/// Get the source file location where the macro is invoked. Returns a `&'static str`. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use minitrace::file_location; | ||
/// | ||
/// fn foo() { | ||
/// assert_eq!(file_location!(), "minitrace/src/macros.rs:8:15"); | ||
/// } | ||
/// # #[cfg(not(target_os = "windows"))] | ||
/// # foo() | ||
#[macro_export] | ||
macro_rules! file_location { | ||
() => { | ||
std::concat!(file!(), ":", line!(), ":", column!()) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters