Skip to content

venkatanagasai6/hello_cargofu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Intro to the cargo

cargo is an package manager tool which manages the project and imported libraryes like the maven project in the java the

##how to create the cargo project

  1. to create the project cargo new eg: cargo new fucker_project

the cargo generates the 1 folder and 1 file

the folder src will contains all the rust program file or .rs files

and the file Cargo.toml will contains the details of the project and depences or libraryes used in the project

##how to run the cargo package

  1. first we need to cd build the project open teminal command : cargo build

the above command will compile and generate the executable file which was located at /target/debug/ and it will also create the Cargo.lock This file keeps track of the exact versions of dependencies in your project. This project doesn’t have dependencies, so the file is a bit sparse. You won’t ever need to change this file manually; Cargo manages its contents for you.

  1. there are 2 ways to run the executable file which was generated by the cargo
    1. run ./target/debug/ in terminal
    2. type cargo run

We just built a project with cargo build and ran it with ./target/debug/hello_cargo, but we can also use cargo run to compile the code and then run the resulting executable all in one command

if the project was alread compiled or project was not modified after compiling once it will just show finish instead of compiling

''' cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs Running target/debug/hello_cargo Hello, world! '''

''' cargo run Compiling hello_cargo v0.1.0 (file:///projects/hello_cargo) Finished dev [unoptimized + debuginfo] target(s) in 0.33 secs Running target/debug/hello_cargo Hello, world!

'''

###we can also just check for the errors that is compile the code whithout producing any executable file by

command : cargo check

##recape Let’s recap what we’ve learned so far about Cargo:

  1. We can build a project using cargo build or cargo check.
  2. We can build and run a project in one step using cargo run.
  3. Instead of saving the result of the build in the same directory as our code, Cargo stores it in the target/debug directory.

##release the code for production

  1. to release the code for production we need to run cargo build --release -> the executable will store at target/release

When your project is finally ready for release, you can use cargo build --release to compile it with optimizations. This command will create an executable in target/release instead of target/debug. The optimizations make your Rust code run faster, but turning them on lengthens the time it takes for your program to compile. This is why there are two different profiles: one for development, when you want to rebuild quickly and often, and another for building the final program you’ll give to a user that won’t be rebuilt repeatedly and that will run as fast as possible. If you’re benchmarking your code’s running time, be sure to run cargo build --release and benchmark with the executable in target/release.

About

explains about the cargo project manager

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages