pub struct Solc {
pub solc: PathBuf,
pub version: Version,
pub base_path: Option<PathBuf>,
pub allow_paths: BTreeSet<PathBuf>,
pub include_paths: BTreeSet<PathBuf>,
pub extra_args: Vec<String>,
}Expand description
Abstraction over solc command line utility
Supports sync and async functions.
By default the solc path is configured as follows, with descending priority:
SOLC_PATHenvironment variable- svm’s
global_version(set viasvm use <version>), stored at<svm_home>/.global_version solcotherwise
Fields§
§solc: PathBufPath to the solc executable
version: VersionCompiler version.
base_path: Option<PathBuf>Value for –base-path arg.
allow_paths: BTreeSet<PathBuf>Value for –allow-paths arg.
include_paths: BTreeSet<PathBuf>Value for –include-paths arg.
extra_args: Vec<String>Additional arbitrary arguments.
Implementations§
source§impl Solc
impl Solc
sourcepub fn new(path: impl Into<PathBuf>) -> Result<Self>
pub fn new(path: impl Into<PathBuf>) -> Result<Self>
A new instance which points to solc. Invokes solc --version to determine the version.
Returns error if solc is not found in the system or if the version cannot be retrieved.
sourcepub fn new_with_args(
path: impl Into<PathBuf>,
extra_args: impl IntoIterator<Item: Into<String>>,
) -> Result<Self>
pub fn new_with_args( path: impl Into<PathBuf>, extra_args: impl IntoIterator<Item: Into<String>>, ) -> Result<Self>
A new instance which points to solc with additional cli arguments. Invokes solc --version to determine the version.
Returns error if solc is not found in the system or if the version cannot be retrieved.
sourcepub fn new_with_version(path: impl Into<PathBuf>, version: Version) -> Self
pub fn new_with_version(path: impl Into<PathBuf>, version: Version) -> Self
A new instance which points to solc with the given version
sourcepub fn source_version_req(source: &Source) -> Result<VersionReq>
pub fn source_version_req(source: &Source) -> Result<VersionReq>
Parses the given source looking for the pragma definition and
returns the corresponding SemVer version requirement.
sourcepub fn find_matching_installation(
versions: &[Version],
required_version: &VersionReq,
) -> Option<Version>
pub fn find_matching_installation( versions: &[Version], required_version: &VersionReq, ) -> Option<Version>
Assuming the versions array is sorted, it returns the first element which satisfies
the provided VersionReq
sourcepub fn find_svm_installed_version(version: &Version) -> Result<Option<Self>>
pub fn find_svm_installed_version(version: &Version) -> Result<Option<Self>>
sourcepub fn svm_home() -> Option<PathBuf>
pub fn svm_home() -> Option<PathBuf>
Returns the directory in which svm stores all versions
This will be:
~/.svmon unix, if it exists- $XDG_DATA_HOME (~/.local/share/svm) if the svm folder does not exist.
sourcepub fn svm_global_version() -> Option<Version>
pub fn svm_global_version() -> Option<Version>
Returns the semver::Version svm’s .global_version is currently set to.
global_version is configured with (svm use <version>)
This will read the version string (eg: “0.8.9”) that the ~/.svm/.global_version file
contains
sourcepub fn installed_versions() -> Vec<Version>
pub fn installed_versions() -> Vec<Version>
Returns the list of all solc instances installed at SVM_HOME
sourcepub fn compile_source(&self, path: &Path) -> Result<CompilerOutput>
pub fn compile_source(&self, path: &Path) -> Result<CompilerOutput>
Convenience function for compiling all sources under the given path
sourcepub fn compile_exact(&self, input: &SolcInput) -> Result<CompilerOutput>
pub fn compile_exact(&self, input: &SolcInput) -> Result<CompilerOutput>
Same as Self::compile(), but only returns those files which are included in the
CompilerInput.
In other words, this removes those files from the CompilerOutput that are not included
in the provided CompilerInput.
§Examples
sourcepub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
pub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
Compiles with --standard-json and deserializes the output as CompilerOutput.
§Examples
use foundry_compilers::{
artifacts::{SolcInput, Source},
compilers::{Compiler, CompilerInput},
solc::Solc,
};
let solc = Solc::new("solc")?;
let input = SolcInput::resolve_and_build(
Source::read_sol_yul_from("./contracts".as_ref()).unwrap(),
Default::default(),
);
let output = solc.compile(&input)?;sourcepub fn compile_as<T: Serialize, D: DeserializeOwned>(
&self,
input: &T,
) -> Result<D>
pub fn compile_as<T: Serialize, D: DeserializeOwned>( &self, input: &T, ) -> Result<D>
Compiles with --standard-json and deserializes the output as the given D.
sourcepub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
pub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
Compiles with --standard-json and returns the raw stdout output.
sourcepub fn version_short(&self) -> Version
pub fn version_short(&self) -> Version
Invokes solc --version and parses the output as a SemVer Version, stripping the
pre-release and build metadata.
sourcepub fn version(solc: impl Into<PathBuf>) -> Result<Version>
pub fn version(solc: impl Into<PathBuf>) -> Result<Version>
Invokes solc --version and parses the output as a SemVer Version.
sourcepub fn version_with_args(
solc: impl Into<PathBuf>,
args: &[String],
) -> Result<Version>
pub fn version_with_args( solc: impl Into<PathBuf>, args: &[String], ) -> Result<Version>
Invokes solc --version and parses the output as a SemVer Version.
sourcepub fn configure_cmd(&self) -> Command
pub fn configure_cmd(&self) -> Command
Configures Command object depeending on settings and solc version used. Some features are only supported by newer versions of solc, so we have to disable them for older ones.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Solc
impl<'de> Deserialize<'de> for Solc
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Ord for Solc
impl Ord for Solc
source§impl PartialOrd for Solc
impl PartialOrd for Solc
impl Eq for Solc
impl StructuralPartialEq for Solc
Auto Trait Implementations§
impl Freeze for Solc
impl RefUnwindSafe for Solc
impl Send for Solc
impl Sync for Solc
impl Unpin for Solc
impl UnwindSafe for Solc
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightBlack.
§Example
println!("{}", value.bright_black());source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightGreen.
§Example
println!("{}", value.bright_green());source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightYellow.
§Example
println!("{}", value.bright_yellow());source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.bright_magenta());source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightWhite.
§Example
println!("{}", value.bright_white());source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlack.
§Example
println!("{}", value.on_bright_black());source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightGreen.
§Example
println!("{}", value.on_bright_green());source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightYellow.
§Example
println!("{}", value.on_bright_yellow());source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlue.
§Example
println!("{}", value.on_bright_blue());source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.on_bright_magenta());source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightCyan.
§Example
println!("{}", value.on_bright_cyan());source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightWhite.
§Example
println!("{}", value.on_bright_white());source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::Underline.
§Example
println!("{}", value.underline());source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::RapidBlink.
§Example
println!("{}", value.rapid_blink());source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);