Giter Club home page Giter Club logo

rustguide's People

Contributors

euledge avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

rustguide's Issues

Chapter 2.0 数当てゲームをプログラムする

プログラムは1から100までの乱数整数を生成します。そしてプレーヤーに予想を入力するよう促します。予想を入力したら、プログラムは、 その予想が小さすぎたか大きすぎたかを出力します。予想が当たっていれば、ゲームは祝福メッセージを表示し、 終了します。

Chapter 1.3 Hello, Cargo!

Cargoは、Rustのビルドシステム兼、パッケージマネージャです。ほとんどのRustaceanはこのツールを使用して、 Rustプロジェクトの管理をしています。Cargoは、コードのビルドやコードが依存しているライブラリのダウンロード、 それらのライブラリのビルドを行ってくれる。この章では以下を学ぶ

  • Cargoの慣習を使用して新しいプロジェクトを作成し、実行する方法

Chapter5 構造体

5.1 構造体の宣言

名と型を指定した複数の変数に名前を付けて複合型として宣言したもの

struct User {
    username: String,
    email: String,
    sign_in_count: u64,
    active: bool
}

Chapter 3.5 フロー制御

3.5.1 if 式

Rust の if 式は 下記のように 条件式を ( ) で囲まなくてもよい。

fn main () {
    let number = 3;

    if number < 5 {
        println!("condition was true");
    } else {
        println!("condition was false");
    }
}

3.5.1.2 let文内でif式を使う

if は 式なのでlet文の右辺に使用することができる。

fn main() {
    let condition = true;
    let number = if condition {
        5
    } else {
        6
    };

    println!("The value of number is : {}", number)
}

また else if で複数の条件になってもよい

fn main() {
    let condition = 5;
    let number = if condition == 1 {
        1
    } else if condition == 2 {
        2
    } else {
        3
    };

    println!("The value of number is : {}", number)
}

ただし、以下のように elseのない if 式のみはコンパイルエラーになる。
多分 if式に当てはまらないときに値が確定できないからだと思う。

    let number = if condition {
        5
    };

異なる型になるのはダメ

fn main() {
    let condition = true;
    let number = if condition {
        5
    } else {
        "six"
    };
    println!("The value of number is : {}", number)
}

Chapter4 所有権を理解する

所有権はRustの特徴的な機能、これがあることでガベージコレクタなしで安全性の担保を行うことができる

Chapter 1.1 Install

  • Rust を Windows10にインストール
  • Rust を Windows10のWSLにインストール

Chapter3.1 変数と可変性

変数と可変性

  • 変数は標準の宣言では不変(immutable)となる
  • 変数を可変としたい場合は mut キーワードをつけて宣言する必要がある。
let mut x = 5;
  • 定数は const で宣言する
  • 定数には型を表す注釈 :u32 が必ず必要
  • 慣例として定数は大文字のスネークケースで表す
const MAX_POINTS: u32 = 100_000;

-数値は位をわかりやすくするためにアンダースコア _を入れることができる。

Chapter 3.3 関数

3.3.1 関数の引数

関数の宣言において、引数を持つ関数定義ができますが、その引数は型を宣言する必要がある。

fn another_function(x: i32) {
    println!("The value of x is: {}", x);
}

Chapter 1.2 Hello, world!

最初のRustプログラムを書きましょう。新しい言語を学ぶ際に、 Hello, world!というテキストを画面に出力する小さなプログラムを書く。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.