公式
https://www.rust-lang.org/
https://blog.rust-lang.org/
https://github.com/rust-lang/rust
公式ドキュメント
https://www.rust-lang.org/learn
Web上の実行環境
https://play.rust-lang.org
※Rustを学びたい人はまず最初に公式のThe Bookを読むこと
https://doc.rust-lang.org/book/
※Rustを学ぶ際に犯しがちな12の過ち
https://dystroy.org/blog/how-not-to-learn-rust
※Rustのasyncについて知りたければ「async-book」は必読
https://rust-lang.github.io/async-book/
※次スレは原則>>980が立てること
前スレ
Rust part28
https://mevius.5ch.net/test/read.cgi/tech/1742805420/
ワッチョイスレ
プログラミング言語 Rust 4【ワッチョイ】
https://mevius.5ch.net/test/read.cgi/tech/1514107621/
Rust part29
■ このスレッドは過去ログ倉庫に格納されています
1デフォルトの名無しさん
2025/05/03(土) 00:47:30.13ID:phVJ5tWC584デフォルトの名無しさん
2025/05/18(日) 13:58:46.67ID:6WAEpSNG >>579
やはりそうなんですね。ありがとうございます。
>>581
>>583
助言ありがとうございます。
ChatGPTにサンプルコード作ってもらいました。コンパイルは通らないですが、やりたいイメージはこんな感じです。
struct Unit {
id: usize,
hp: i32,
}
impl Unit {
fn act(&mut self, all_units: &mut Vec<Unit>) {
// 自分以外のユニットに攻撃したい
for unit in all_units.iter_mut() {
if unit.id != self.id {
unit.hp -= 10;
}
}
}
}
fn main() {
let mut units = vec![
Unit { id: 0, hp: 100 },
Unit { id: 1, hp: 80 },
Unit { id: 2, hp: 60 },
];
for unit in units.iter_mut() {
unit.act(&mut units); // ❌ コンパイルエラーになるが、やりたいことはこんな感じ
}
}
やはりそうなんですね。ありがとうございます。
>>581
>>583
助言ありがとうございます。
ChatGPTにサンプルコード作ってもらいました。コンパイルは通らないですが、やりたいイメージはこんな感じです。
struct Unit {
id: usize,
hp: i32,
}
impl Unit {
fn act(&mut self, all_units: &mut Vec<Unit>) {
// 自分以外のユニットに攻撃したい
for unit in all_units.iter_mut() {
if unit.id != self.id {
unit.hp -= 10;
}
}
}
}
fn main() {
let mut units = vec![
Unit { id: 0, hp: 100 },
Unit { id: 1, hp: 80 },
Unit { id: 2, hp: 60 },
];
for unit in units.iter_mut() {
unit.act(&mut units); // ❌ コンパイルエラーになるが、やりたいことはこんな感じ
}
}
585デフォルトの名無しさん
2025/05/18(日) 14:03:53.58ID:UzOJGd+R >>584
これも追加
// 自分以外のユニットに攻撃したい
↓
// 自分以外のユニットから奪い取る
if unit.id != self.id {
unit.hp -= 10;
self.hp += 10;
}
これも追加
// 自分以外のユニットに攻撃したい
↓
// 自分以外のユニットから奪い取る
if unit.id != self.id {
unit.hp -= 10;
self.hp += 10;
}
■ このスレッドは過去ログ倉庫に格納されています
