«前の日記(2017-07-21) 最新 次の日記(2017-07-23)» 編集

ToDo:

  • 99 深呼吸して、おちけつ (~12/31 あと287日)
  • 98 毎日アウトプットを重きにおいた目標をたてる (~12/31 あと287日)
  • 97 買物は行動を変えるもの・ことに限る (~12/31 あと287日)
  • 96 合理的な行動はときに我慢を強いる(~12/31 あと287日)

ɥozɐʞıɥ


2017-07-22 相方誕生日プレゼント [長年日記]

_ [買物][] 忍物語

8/12 13と終物語 (下)が放送です。

_ [買物][BD][映画] 傷物語 I 鉄血篇

この日に映画を観ました。

_ [買物][映画][BD] 傷物語 II熱血篇

この日に映画を観ました。

_ [買物][映画][BD] 傷物語 III冷血篇

この日に映画を観ました。

_ [モフ太] 散歩

ヲレのリハビリですな。

モフ太さんぽ
モフ太さんぽ posted by (C)ひかぞぉ

_ [Rust] Mutableと借用

これコンパイルエラーです。

fn main() {

let mut x = 5;

let y = &mut x;

*y = 1;

println!("{}",y);

println!("{}",x);

}

yがxを借用しているのだがそのyの生存期間がxより早く終わらない

error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable

--> src/main.rs:8:19

|

4 | let y = &mut x;

| - mutable borrow occurs here

...

8 | println!("{}",x);

| ^ immutable borrow occurs here

9 | }

| - mutable borrow ends here

error: aborting due to previous error

だから{}でyの生存期間を短くしてやると通る

fn main() {

let mut x = 5;

{

let y = &mut x;

*y = 1;

println!("{}",y);

}

println!("{}",x);

}

あと*yで参照の実体*1を変更しているので出力は

1

1

です。

*1 表現あってる?

_ [Rust] Mutable

これは通る

fn main() {

let spaces = " ";

let spaces = spaces.len();

println!("{}",spaces);

}

がこれは警告で通る

fn main() {

let mut spaces = " ";

let spaces = spaces.len();

println!("{}",spaces);

}

Compileメッセージ

 warning: variable does not need to be mutable

 --> src/main.rs:2:9

  |

2 | let mut spaces = " ";

  | ^^^^^^^^^^

  |

 = note: #[warn(unused_mut)] on by default

Finished dev [unoptimized + debuginfo] target(s) in 0.32 secs

Running `target/debug/study`

1



2002|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|
«前の日記(2017-07-21) 最新 次の日記(2017-07-23)» 編集