There are essentially three steps to using a library within your Rust application:
- Including the dependency.
- Writing code that uses the library.
- Building your application to link to the library.
The most difficult stage is the second as it requires writing code, call back code, and other such wrappers to use the library.
As with using any library not provided by Prelude
, the compiler has to know of the existence of the library. As we did in Chapter 8, The Rust Application Lifetime, we let the compiler know to expect an external library by including in the Cargo.toml
file, as follows:
[dependency] libc = "0.2.0"
The figure in quotes is the library version. This is useful to have in as it enables the compiled Rust application to only run against a particular version of the library, which guarantees the code required will be in the library. The downside is that in order to always ensure the library is available, the compiled binary will need to ship...