zoukankan      html  css  js  c++  java
  • Cargo, Rust’s Package Manager

    http://doc.crates.io/

    Installing

    The easiest way to get Cargo is to get the current stable release of Rust by using the rustup script:

    $ curl -sSf https://static.rust-lang.org/rustup.sh | sh
    

    This will get you the current stable release of Rust for your platform along with the latest Cargo.

    If you are on Windows, you can directly download the latest 32bit (Rust and Cargo) or 64bit (Rust andCargo) Rust stable releases or Cargo nightlies.

    Alternatively, you can build Cargo from source.

    Let’s get started

    To start a new project with Cargo, use cargo new:

    $ cargo new hello_world --bin
    

    We’re passing --bin because we’re making a binary program: if we were making a library, we’d leave it off.

    Let’s check out what Cargo has generated for us:

    $ cd hello_world
    $ tree .
    .
    ├── Cargo.toml
    └── src
        └── main.rs
    
    1 directory, 2 files
    

    This is all we need to get started. First, let’s check out Cargo.toml:

    [package]
    name = "hello_world"
    version = "0.1.0"
    authors = ["Your Name <you@example.com>"]
    

    This is called a manifest, and it contains all of the metadata that Cargo needs to compile your project.

    Here’s what’s in src/main.rs:

    fn main() {
        println!("Hello, world!");
    }

    Cargo generated a “hello world” for us. Let’s compile it:

    $ cargo build
       Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)

    And then run it:

    $ ./target/debug/hello_world
    Hello, world!
    

    We can also use cargo run to compile and then run it, all in one step:

    $ cargo run
         Fresh hello_world v0.1.0 (file:///path/to/project/hello_world)
       Running `target/hello_world`
    Hello, world!

    Going further

    For more details on using Cargo, check out the Cargo Guide

  • 相关阅读:
    git 命令
    减少死锁的几个常用方法
    JFinal SQL in 查询排序
    并发编程中,如何减少上下文切换
    MySql批量更新
    百度编辑器上传图片自定义路径,访问路径动态加载
    百度编辑器不能插入html标签解决方法
    搭建贴吧自动签到服务
    mpv设置CPU软解
    使用Vercel+Github搭建个人博客
  • 原文地址:https://www.cnblogs.com/zengkefu/p/6979613.html
Copyright © 2011-2022 走看看