External packages (crates)
Course: Rust for Solana contracts - chapter 17
cargo add module_nameCargo.toml
Section titled “Cargo.toml”
[package]name = "rust"version = "0.1.0"edition = "2021"
[dependencies]reqwest = "0.12.12"Features in external crates
Section titled “Features in external crates”You can optionally get some features of an external crate if you dont need the full crate/need some extra features when installing the crate.
[dependencies]reqwest = { version = "0.12.12", features = ["json"], }serde = { version = "0.12.12", features = ["derive"] }Try some packages locally
Section titled “Try some packages locally”- chrono
- dotenv
- uuid
- tui
- thiserror
- sqlx
chrono
Section titled “chrono”Chrono lets you do data and time in rust
https://docs.rs/chrono/latest/chrono

use chrono::{Local, Utc};
fn main() { let utc_time = Utc::now(); let local_time = Local::now(); println!("local time is {}", utc_time); println!("native time is {}", local_time);}dotenv
Section titled “dotenv”use dotenv::dotenv;use std::env;
fn main() { dotenv().ok(); let var = env::var("REDIS_ADDRESS").unwrap(); println!("{}", var);}use uuid::Uuid;
fn main() { let random_uuid = Uuid::new_v4(); println!("{}", random_uuid);}Cargo.toml
uuid = {version = "1.14.0", features = ["v4", "fast-rng"]}💡
If you dont add the v4 feature, notice you cant access the new_v4 function
