rustの構造体を使って以下のことを実装したい
set_enable関数はenabledをtrue(1)にする
set_direction関数はenabledがtrueではないとき処理を抜け、trueである場合directionをtrueに
set_output_statusはenabledがtrueではないかつdirectionもtrueではないとき処理を抜け
trueである場合 outputをtrueにする
rust
struct Gpio{ enabled:bool, direction:bool, output:bool, mode:u32 } impl Gpio{ pub fn set_enable(&mut self){ self.enabled=true; } pub fn set_direction(&mut self){ if self.enabled=!true{ Err(); } self.direction=true; } pub fn set_output_status(&mut self){ if self.enabled=!true{ Err(); } if self.direction=!true{ Err(); } self.output=true; } } fn main(){ let mut gpio=Gpio{ enabled:true, direction:true, output:true, }; gpio.set_enable(); let pin=gpio.set_enable(); println!("{}",pin); }
実行すると以下のようなエラーが出ますがどこをどう修正すればいいかわかりません
助言をお願いしたいです
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.
まだ回答がついていません
会員登録して回答してみよう