Code Reuse
In EDK II, code reuse was done using LibraryClasses
. In Rust, we do not use Rust Traits
for code-reuse.
Instead we use Rust crates
. See some of the generic reading here:
When creating crates that are being published, you should do your best to make your crates dependency versions at least
specific as possible. What this means is that if possible, do not do crate_dependency == "1.42.8"
. Instead do
crate_dependency == "1.*"
if any version between 1 and two is expected to work. crate_dependency == "1"
is
equivalent if you do not want to use wildcards. See
Version Requirement Syntax
for specifics.
Cargo will do its best to resolve dependency requirements down to a single version of each crate. However, if it can't, it will simply download and compile multiple versions of the same crate. This has a couple of issues:
- It increases compile time
- It can bloat the size
- It can cause API expectations to break resulting in compilation failures
What (3) means is that TraitA
in Crate1
version 1.0.0
will be treated as a completely different trait than
TraitA
in Crate1
version 1.0.1
. You'll end up seeing compilation errors such as the following, when it worked
previously.
^^^^^^^ the trait `XXXXX` is not implemented for `YYYYYYY`