new and getter

This commit is contained in:
2024-09-07 15:30:22 -04:00
parent 0c36b899da
commit 5b5b749738
2 changed files with 13 additions and 5 deletions

View File

@@ -1,4 +1,14 @@
pub struct StateOwner { pub struct StateOwner {
pub state: String, state: String,
} }
impl StateOwner {
pub fn new(state: String) -> StateOwner {
StateOwner { state }
}
pub fn get_state(&self) -> &str {
&self.state
}
}

View File

@@ -4,9 +4,7 @@ use state_queue::StateOwner;
fn create_state_owner() { fn create_state_owner() {
//this test is just to show how to initialize state //this test is just to show how to initialize state
//and verify that cargo test is actually working //and verify that cargo test is actually working
let example = StateOwner{ let example = StateOwner::new(String::from("State Owner Created!"));
state: String::from("State Owner Created!"),
};
assert_eq!(example.state, "State Owner Created!"); assert_eq!(example.get_state(), "State Owner Created!");
} }