Skip to content

Commit

Permalink
feat: impl .path(&self) for ContractInfo (#250)
Browse files Browse the repository at this point in the history
Ref:
foundry-rs/foundry#9770 (comment)

Smol convenience fn for `ContractInfo` to retrieve the `Path`.
  • Loading branch information
yash-atreya authored Feb 12, 2025
1 parent f968ffe commit 6acbb69
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/compilers/src/compile/output/info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Commonly used identifiers for contracts in the compiled output.
use std::{borrow::Cow, fmt, str::FromStr};
use std::{borrow::Cow, fmt, path::Path, str::FromStr};

#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[error("{0}")]
Expand Down Expand Up @@ -40,6 +40,11 @@ impl ContractInfo {
pub fn new(info: &str) -> Self {
info.parse().unwrap_or_else(|_| Self { path: None, name: info.to_string() })
}

/// Returns the path to the contract source file if provided.
pub fn path(&self) -> Option<&Path> {
self.path.as_deref().map(Path::new)
}
}

impl fmt::Display for ContractInfo {
Expand Down

0 comments on commit 6acbb69

Please sign in to comment.