Skip to content

Commit b250109

Browse files
committed
Store module_path as Cow
1 parent 8913759 commit b250109

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tracing-core/src/metadata.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct Metadata<'a> {
7272

7373
/// The name of the Rust module where the span occurred, or `None` if this
7474
/// could not be determined.
75-
module_path: Option<&'a str>,
75+
module_path: Option<Cow<'a, str>>,
7676

7777
/// The name of the source code file where the span occurred, or `None` if
7878
/// this could not be determined.
@@ -139,6 +139,13 @@ impl<'a> Metadata<'a> {
139139
None
140140
}
141141
};
142+
let module_path = {
143+
if let Some(module_path) = module_path {
144+
Some(Cow::Borrowed(module_path))
145+
} else {
146+
None
147+
}
148+
};
142149
Metadata {
143150
name: Cow::Borrowed(name),
144151
target: Cow::Borrowed(target),
@@ -177,8 +184,8 @@ impl<'a> Metadata<'a> {
177184

178185
/// Returns the path to the Rust module where the span occurred, or
179186
/// `None` if the module path is unknown.
180-
pub fn module_path(&self) -> Option<&'a str> {
181-
self.module_path
187+
pub fn module_path(&'a self) -> Option<&'a str> {
188+
self.module_path.as_ref().map(|p| p.as_ref() )
182189
}
183190

184191
/// Returns the name of the source code file where the span

0 commit comments

Comments
 (0)