or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Rust勉強会 第3回
4章 構造体で構造化!
2020/08/21 堀川由人
本日のメニュー
プレゼン20分くらい+議論10分位で18:30前後終了を目指します。
構造体の定義
struct構文
構造体を定義する
インスタンス作成
インスタンスをつくる(順番は気にしなくてOK)
フィールドの変更(2/2)
エラーになる例
フィールドの変更(2/2)
ここでもフィールドを変更する場合は
mut
が必要インスタンスを作る関数(1/2)
2つの
String
引数を取ってUser
を返すインスタンスを作る関数(2/2)
実は省略可能
インスタンスの構成(他からの参照)
他の
user2
を定義. ただし足りないものはuser1
からほぼタプルの構造体
引数の順番のみが重要な場合
(個人的にはRGBかBGRを明記したいので避けたい)
プログラム例
長方形の面積(愚直に)
長方形の面積(構造体)
Rectangleのprintln!(1/2)
これはエラー(標準的なRectangle->Stringが無い)
Rectangleのprintln!(2/2)
#[derive(Debug)]
でRectangleにデバッグ宣言{:?}
で構造体をよしなに文字列に変換メソッドなど
Rectangle
impl <struct>
内にメソッドを定義implement: 実装
implの書き方
分かれててもok
複数のRectangle
関連関数
として正方形が定義できる.
関連関数はメソッドとは呼ばれない
まとめ・所感
まとめ
struct
impl
fieldについて
mut
が必要(Rustでは当たり前なのだとと思いますが)Juliaでは
によってfieldの変更可能/不能な構造体を分けていたので少し意外に感じました
モチベーション
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →参考資料
https://doc.rust-jp.rs/book/second-edition/ch05-00-structs.html