0% found this document useful (0 votes)
5 views1 page

CargoCheatSheet 2

This document provides an overview of Rust and its package manager, Cargo, including a simple 'Hello, World!' example. It outlines key Cargo commands for building, running, testing, and documenting projects, as well as how to install Rust and Cargo using Rustup. Additionally, it lists some of the most downloaded crates and mentions JFrog Artifactory's support for Cargo registries.

Uploaded by

yasir marwat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

CargoCheatSheet 2

This document provides an overview of Rust and its package manager, Cargo, including a simple 'Hello, World!' example. It outlines key Cargo commands for building, running, testing, and documenting projects, as well as how to install Rust and Cargo using Rustup. Additionally, it lists some of the most downloaded crates and mentions JFrog Artifactory's support for Cargo registries.

Uploaded by

yasir marwat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CARGO CHEAT SHEET SIMPLE HELLO WORLD EXAMPLE

RUST PACKAGE MANAGER Step 1: Create a new file called hello.rs, with the following:
HOW TO USE CARGO?
fn main() {
println!("Hello, world!");
WHAT IS RUST AND WHY DO WE LOVE IT? }
Cargo is a smart client that gives you the ability to build, run and test your
projects. Here are some useful Cargo commands that take you through a Step 2: Compile it by running the following command:
typical workflow: $ rustc hello.rs
Rust was introduced in 2010 by Graydon Hoare of
Mozilla Research. Rust is a low-level • Build your project: Run the binary that just created (hello) by running the following
$ cargo build command:
statically-typed multi-paradigm programming
language that’s focused on safety and $ ./hello
performance, similar to C and C++, and is fast and • Run your project:
memory-efficient with no garbage collections. $ cargo run

According to the StackOverflow surveys, Rust has • Test your project:


been the most loved programming language for $ cargo test MOST DOWNLOADED CRATES
the last five years in a row! Build documentation for your project:

What is Cargo? $ cargo doc
Cargo is the Rust package manager. Cargo
downloads your Rust package dependencies, • Publish a library to crates.io:
$ cargo publish In Rust a library or executable program is called a crate. Crates are
compiles your packages, makes distributable
compiled using the Rust compiler, rustc. Here are the most
packages, and uploads them to crates.io by
downloaded crates*:
default, the Rust community's package registry.
Rand - A Rust library for random number generation.
CODING IN RUST Syn - A parsing library for parsing a stream of Rust tokens into a syntax
tree of Rust source code.
HOW TO INSTALL RUST AND CARGO Libc - A library that provides all of the definitions necessary to easily
interoperate with C code on each of the platforms that Rust supports.
Import external crate Quote - A library that provides the quote! macro for turning Rust
syntax tree data structures into tokens of source code.
extern crate rand; //external dependency
use rand::Rng; //bring Rng trait which defines the methods into Rand_core - Core traits and error types of the rand library, plus tools
The easiest way to install Rust is with a tool called Rustup, which is a Rust
scope for implementing RNGs.
installer and version management tool.
*Last updated on April 2021
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh Data Structures
Rust updates are very frequent, so if you have installed Rustup some time struct S {} Define a struct with named fields.
ago, chances are your Rust version is out of date. To get the latest version enum E {} Define an enum
of Rust run the following command: const X: T = T(); Define constant CARGO & JFROG
static X: T = T(); Global variable static with a single memory location
$ rustup update let x: T; Allocate T bytes in stack bound as X assigned once not mutable Today JFrog Artifactory natively supports Cargo registries
for the Rust programming language, providing full control
When you install Rustup you’ll get the latest stable version of the Rust build Control Flow of your deployment and resolution of Cargo packages.
tool and package manager, also known as Cargo.
while x {} Loop , run while expression x is true. A Cargo registry can be used to proxy remote Cargo
loop {} Loop infinitely until break . Can yield value with break x . resources and cache downloaded packages. Secure your
if x {} else {} Conditional branch if expression is true. packages using a local Cargo repository and much more.
break Break expression to exit a loop.
continue Continue expression to the next loop iteration of this loop. Read more about Cargo repositories >

You might also like