Struct ethers_solc::remappings::Remapping
source · pub struct Remapping {
pub context: Option<String>,
pub name: String,
pub path: String,
}
Expand description
The solidity compiler can only reference files that exist locally on your computer. So importing directly from GitHub (as an example) is not possible.
Let’s imagine you want to use OpenZeppelin’s amazing library of smart contracts,
@openzeppelin/contracts-ethereum-package
:
pragma solidity 0.5.11;
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
contract MyContract {
using SafeMath for uint256;
...
}
When using solc
, you have to specify the following:
- A
prefix
: the path that’s used in your smart contract, i.e.@openzeppelin/contracts-ethereum-package
- A
target
: the absolute path of the downloaded contracts on your computer
The format looks like this: solc prefix=target ./MyContract.sol
For example:
solc --bin \
@openzeppelin/contracts-ethereum-package=/Your/Absolute/Path/To/@openzeppelin/contracts-ethereum-package \
./MyContract.sol
You can also specify a context
which limits the scope of the remapping to a subset of your
project. This allows you to apply the remapping only to imports located in a specific library or
a specific file. Without a context a remapping is applied to every matching import in all files.
The format is: solc context:prefix=target ./MyContract.sol
Fields§
§context: Option<String>
§name: String
§path: String
Implementations§
source§impl Remapping
impl Remapping
sourcepub fn into_relative(self, root: impl AsRef<Path>) -> RelativeRemapping
pub fn into_relative(self, root: impl AsRef<Path>) -> RelativeRemapping
Convenience function for RelativeRemapping::new
sourcepub fn strip_prefix(&mut self, base: impl AsRef<Path>) -> &mut Self
pub fn strip_prefix(&mut self, base: impl AsRef<Path>) -> &mut Self
Removes the base
path from the remapping
source§impl Remapping
impl Remapping
sourcepub fn find_many_str(path: &str) -> Vec<String>
pub fn find_many_str(path: &str) -> Vec<String>
Returns all formatted remappings
sourcepub fn find_many(dir: impl AsRef<Path>) -> Vec<Remapping>
pub fn find_many(dir: impl AsRef<Path>) -> Vec<Remapping>
Attempts to autodetect all remappings given a certain root path.
This will recursively scan all subdirectories of the root path, if a subdirectory contains a solidity file then this a candidate for a remapping. The name of the remapping will be the folder name.
However, there are additional rules/assumptions when it comes to determining if a candidate should in fact be a remapping:
All names and paths end with a trailing “/”
The name of the remapping will be the parent folder of a solidity file, unless the folder is
named src
, lib
or contracts
in which case the name of the remapping will be the parent
folder’s name of src
, lib
, contracts
: The remapping of repo1/src/contract.sol
is
name: "repo1/", path: "repo1/src/"
Nested remappings need to be separated by src
, lib
or contracts
, The remapping of
repo1/lib/ds-math/src/contract.sol
is name: "ds-math/", "repo1/lib/ds-math/src/"
Remapping detection is primarily designed for dapptool’s rules for lib folders, however, we
attempt to detect and optimize various folder structures commonly used in node_modules
dependencies. For those the same rules apply. In addition, we try to unify all
remappings discovered according to the rules mentioned above, so that layouts like,
which would be multiple rededications according to our rules (“governance”, “protocol-v2”),
are unified into @aave
by looking at their common ancestor, the root of this subdirectory
(@aave
)
sourcepub fn slash_path(&mut self)
pub fn slash_path(&mut self)
Converts any \\
separators in the path
to /
Trait Implementations§
source§impl<'de> Deserialize<'de> for Remapping
impl<'de> Deserialize<'de> for Remapping
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 From<RelativeRemapping> for Remapping
impl From<RelativeRemapping> for Remapping
source§fn from(r: RelativeRemapping) -> Self
fn from(r: RelativeRemapping) -> Self
source§impl From<Remapping> for RelativeRemapping
impl From<Remapping> for RelativeRemapping
source§impl Ord for Remapping
impl Ord for Remapping
source§impl PartialEq for Remapping
impl PartialEq for Remapping
source§impl PartialOrd for Remapping
impl PartialOrd for Remapping
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Remapping
impl StructuralPartialEq for Remapping
Auto Trait Implementations§
impl RefUnwindSafe for Remapping
impl Send for Remapping
impl Sync for Remapping
impl Unpin for Remapping
impl UnwindSafe for Remapping
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.