Skip to content

Commit 6acbb69

Browse files
authored
feat: impl .path(&self) for ContractInfo (#250)
Ref: foundry-rs/foundry#9770 (comment) Smol convenience fn for `ContractInfo` to retrieve the `Path`.
1 parent f968ffe commit 6acbb69

File tree

1 file changed

+6
-1
lines changed
  • crates/compilers/src/compile/output

1 file changed

+6
-1
lines changed

crates/compilers/src/compile/output/info.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Commonly used identifiers for contracts in the compiled output.
22
3-
use std::{borrow::Cow, fmt, str::FromStr};
3+
use std::{borrow::Cow, fmt, path::Path, str::FromStr};
44

55
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
66
#[error("{0}")]
@@ -40,6 +40,11 @@ impl ContractInfo {
4040
pub fn new(info: &str) -> Self {
4141
info.parse().unwrap_or_else(|_| Self { path: None, name: info.to_string() })
4242
}
43+
44+
/// Returns the path to the contract source file if provided.
45+
pub fn path(&self) -> Option<&Path> {
46+
self.path.as_deref().map(Path::new)
47+
}
4348
}
4449

4550
impl fmt::Display for ContractInfo {

0 commit comments

Comments
 (0)