Guide-Rust

Introduction

This guide will walk you through the process of creating a Rust Crate, building it, pushing it to Gemfury, and then installing it. Before you get started, be sure you have the following:

Creating a crate

To create a crate, you only need a Cargo.toml manifest file and an entrypoint in the project’s src subdirectory. However, most crates include libraries, tests, documentation, and more. To quickly create a scaffold that includes these, we recommend using Cargo’s generator:

cargo new CRATE_NAME

This will create a directory CRATE_NAME with the initial crate structure including the Cargo.toml manifest and src/main.rs entrypoint.

Once it’s ready, build and test it with the cargo command:

 

Upload your crate

Now that you have the structure of the crate in place, you have a number of ways to upload it to your Gemfury account. You can use the Dashboard, cURL, or the Gemfury CLI.

Pushing from terminal

You already have a prebuilt crate after running cargo package, so let’s upload it directly from a terminal:

curl -F package=@target/package/CRATE_NAME-0.1.0.crate \
     https://TOKEN@push.fury.io/USERNAME/

If you’ve installed the Gemfury CLI, you can also push with:

fury push CRATE_NAME-0.1.0.crate --as USERNAME
Pushing from a browser

You can upload your crates via Gemfury Dashboard. Open the Upload dialog or just drag-and-drop the crate directly into the browser window.

 

Install crates with Cargo

Using Gemfury with Cargo is easy, just add a registries block with your Repo-URL to the project’s .cargo/config.toml file:

[registries.fury]
index = "sparse+https://crates.fury.io/USERNAME/"
credential-provider = "cargo:token"

Once you’ve defined the registry, you can set individual dependencies in the project’s Cargo.toml to be retrieved from your Gemfury Crates registry:

[dependencies]
your-crate = { version = "1.0", registry = "fury" }
Authenticating for private crates

To access private crates, you will need to authenticate using a deploy token. You can do this with an environment variable. The environment variable name is derived from your registry name. Since we chose fury, we authenticate as follows: