diff --git a/cargo-insta/src/cargo.rs b/cargo-insta/src/cargo.rs index 65861328..f118142b 100644 --- a/cargo-insta/src/cargo.rs +++ b/cargo-insta/src/cargo.rs @@ -71,7 +71,7 @@ impl PendingSnapshot { pub fn summary(&self) -> String { use std::fmt::Write; let mut rv = String::new(); - if let Some(ref source) = self.new.metadata().source { + if let Some(source) = self.new.metadata().source() { write!(&mut rv, "{}", source).unwrap(); } if let Some(line) = self.line { diff --git a/src/snapshot.rs b/src/snapshot.rs index 4ba3a710..f4dc0db4 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -72,13 +72,24 @@ impl PendingInlineSnapshot { pub struct MetaData { /// The source file (relative to workspace root). #[serde(skip_serializing_if = "Option::is_none")] - pub source: Option, + pub(crate) source: Option, /// Optionally the expression that created the snapshot. #[serde(skip_serializing_if = "Option::is_none")] - pub expression: Option, + pub(crate) expression: Option, } impl MetaData { + /// Returns the absolute source path. + pub fn source(&self) -> Option<&str> { + self.source.as_deref() + } + + /// Returns the expression that created the snapshot. + pub fn expression(&self) -> Option<&str> { + self.expression.as_deref() + } + + /// Returns the relative source path. pub fn get_relative_source(&self, base: &Path) -> Option { self.source.as_ref().map(|source| { base.join(source)