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 crates.io page: https://crates.io/crates/svg, i.e. under the already existing [dependencies] section, you write

[dependencies]
svg = "0.10.0"
1 Like

FYI:

1 Like

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

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.