How to import library crate properly?

Disclaimer - I am very, very new to Rust and the ecosystem.

That being said I am having an issue trying to use a library crate (svg - Rust) in my project and think am obviously missing something fundamental.

I have copied the code from the example but am getting a number of compiler errors e.g.

use of undeclared crate or module 'svg'

Here is a link to a playground Rust Playground

In the playground this won't work because it doesn't include that svg crate. Locally, on your machine, you'll have to create a cargo project (in case you haven't already and instead were using rustc manually before, you need to set up the project directory and files and then switch to using commands such as cargo check or cargo run), for an introduction see

Hello, Cargo! - The Rust Programming Language

The can add the dependency in the Cargo.toml file by adding the line advertised (under the heading/section “Install”) on the crate's page:, i.e. under the already existing [dependencies] section, you write

svg = "0.10.0"
1 Like


1 Like

All working now, thanks very much @steffahn :slight_smile: