About the structure of trust

Asked 2 years ago, Updated 2 years ago, 65 views

After running the function set_enable in the following example, I would like to check if enabled is true.
How do I invoke enabled in the main function?

structure Gpio{
    enabled:bool,
    direction:bool,
    output:bool,
    //periph —GPIO_CONFIG,
}

impl Gpio{
    pubfn set_enable(&mut self){
        self.enabled = true;
    }

    pubfn set_direction(&mut self){
        if self.enabled!=true{
            return;
        }
        self.direction=true;
    }

    pubfn set_output_status(&mut self){
        if self.enabled!=true{
            return;
        }
        if self.direction!=true{
            return;
        }
        self.output = true;
    }
}

US>fnmain(){
    let mutpin = Gpio {
        enabled: false,
        direction: false,
        output: false,
    };
    
    println!
}

rust

2022-09-30 11:32

1 Answers

I just called it and it came out without any problems.

fnmain(){
    let mutpin = Gpio {
        enabled: false,
        direction: false,
        output: false,
    };
    
    if pin.enabled {
        print!("pin.enabled is true");
    } else{
        print!("pin.enabled is false");
    }
}


2022-09-30 11:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.