rustの構造体を使って以下のことを実装したい
set_enable関数はenabledをtrue(1)にする
set_direction関数はenabledがtrueではないとき処理を抜け、trueである場合directionをtrueに
set_output_statusはenabledがtrueではないかつdirectionもtrueではないとき処理を抜け
trueである場合 outputをtrueにする
rust
1struct Gpio{ 2 enabled:bool, 3 direction:bool, 4 output:bool, 5 mode:u32 6} 7 8impl Gpio{ 9 pub fn set_enable(&mut self){ 10 self.enabled=true; 11 } 12 13 pub fn set_direction(&mut self){ 14 if self.enabled=!true{ 15 Err(); 16 } 17 self.direction=true; 18 } 19 20 pub fn set_output_status(&mut self){ 21 if self.enabled=!true{ 22 Err(); 23 } 24 if self.direction=!true{ 25 Err(); 26 } 27 self.output=true; 28 } 29} 30 31fn main(){ 32 let mut gpio=Gpio{ 33 enabled:true, 34 direction:true, 35 output:true, 36 }; 37 gpio.set_enable(); 38 let pin=gpio.set_enable(); 39 println!("{}",pin); 40}
実行すると以下のようなエラーが出ますがどこをどう修正すればいいかわかりません
助言をお願いしたいです
rror[E0425]: cannot find value `enabled` in this scope --> src\main.rs:10:9 | 10 | enabled=true; | ^^^^^^^ help: you might have meant to use the available field: `self.enabled` error[E0425]: cannot find value `enabled` in this scope --> src\main.rs:14:12 | 14 | if enabled=!true{ | ^^^^^^^ | help: you might have meant to use pattern matching | 14 | if let enabled=!true{ | ^^^ help: you might have meant to use the available field | 14 | if self.enabled=!true{ | ^^^^^^^^^^^^ error[E0425]: cannot find value `direction` in this scope --> src\main.rs:17:9 | 17 | direction=true; | ^^^^^^^^^ help: you might have meant to use the available field: `self.direction` error[E0425]: cannot find value `enabled` in this scope --> src\main.rs:21:12 | 21 | if enabled=!true{ | ^^^^^^^ | help: you might have meant to use pattern matching | 21 | if let enabled=!true{ | ^^^ help: you might have meant to use the available field | 21 | if self.enabled=!true{ | ^^^^^^^^^^^^ error[E0425]: cannot find value `direction` in this scope --> src\main.rs:24:12 | 24 | if direction=!true{ | ^^^^^^^^^ | help: you might have meant to use pattern matching | 24 | if let direction=!true{ | ^^^ help: you might have meant to use the available field | 24 | if self.direction=!true{ | ^^^^^^^^^^^^^^ error[E0425]: cannot find value `output` in this scope --> src\main.rs:27:9 | 27 | output=true; | ^^^^^^ help: you might have meant to use the available field: `self.output` error[E0061]: this function takes 1 argument but 0 arguments were supplied --> src\main.rs:15:13 | 15 | Err(); | ^^^-- supplied 0 arguments | | | expected 1 argument error[E0061]: this function takes 1 argument but 0 arguments were supplied --> src\main.rs:22:13 | 22 | Err(); | ^^^-- supplied 0 arguments | | | expected 1 argument error[E0061]: this function takes 1 argument but 0 arguments were supplied --> src\main.rs:25:13 | 25 | Err(); | ^^^-- supplied 0 arguments | | | expected 1 argument error[E0063]: missing field `mode` in initializer of `Gpio` --> src\main.rs:32:18 | 32 | let mut gpio=Gpio{ | ^^^^ missing `mode` error[E0277]: `()` doesn't implement `std::fmt::Display` --> src\main.rs:39:19 | 39 | println!("{}",pin); | ^^^ `()` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `()` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: required by `std::fmt::Display::fmt` = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 11 previous errors Some errors have detailed explanations: E0061, E0063, E0277, E0425. For more information about an error, try `rustc --explain E0061`. error: could not compile `test_cargo` To learn more, run the command again with --verbose.
回答1件
あなたの回答
tips
プレビュー