Learning rust - Day 01

Learning rust - Day 01

Hey there,

Okay, this is the second day of my #NoZeroDaysOfCode in Rust. In the previous article it is all about just the basic setup of Rust in our system, especially it focuses on Ubuntu installation of rust.

On this day 01, I learnt serveral new stuffs in rust such as below.

  • Came to know about a new term in Rust which is Cargo.
  • Cargo is just like any other package manager available for Javascript/Java/Any other lanuguages.
  • Cargo takes incharge of compiling and building your source code and also it can be used for installing anyother 3rd party or open-source dependencies.
  • If you would've followed my article on installing rust using one command, it takes care for you to setup Cargo in your system as well.
  • To ensure Cargo is installed in your system, run the below command.

$ cargo --version        

  • For example, if we want to generte a random number, rust don't have any inbuilt functions for doing it. That's when this Cargo package manager becomes handy. Got it?!
  • So every code we write using Cargo as a package manager is going to be called as Crates. In crates there are two categories,
  • 1. Binary Crate : The code which we write for some business logic applications.
  • 2. Library Crate : The code that can be used inside other codes
  • Since we are using package manager Cargo which can be used for external dependencies , it is important to maintain consistency of external crate's versions. That's why rust have Cargo.lock file.
  • Cargo.lock file is to ensure no version changes to external crates breaks our code.
  • Specifically, the crates.io registry is maintained as a Git repository that's updated automatically whenever a new version of a package is released. The registry only contains the names of crates and some metadata about them, mainly the versions and which other crates they depend on. Fetching the source code for a package like rand is a separate step.
  • ?Cargo needs to know what versions of crates are available so it can create Cargo.lock in a new project, or update Cargo.lock with the latest versions of packages when you run cargo update.
  • To use cargo for creating the project have a look in here.
  • Using the official doc with help of cargo did a hello world program today.

See you on Day 2

要查看或添加评论,请登录

Immanuel John的更多文章

  • Pattern Matching in Rust

    Pattern Matching in Rust

    Pattern matching is one of the most powerful features of Rust programming language. It allows developers to match…

    4 条评论
  • Rust Variables & Mutability

    Rust Variables & Mutability

    Rust is known for its strict and safe approach to programming, and one of the most unique features of the language is…

    1 条评论
  • Learning rust - Day 0

    Learning rust - Day 0

    Hey community, Currently I have got an opportunity to start learning Rust Programming Language which seems a very…

社区洞察

其他会员也浏览了