new and getter
This commit is contained in:
12
src/lib.rs
12
src/lib.rs
@@ -1,4 +1,14 @@
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,7 @@ use state_queue::StateOwner;
|
||||
fn create_state_owner() {
|
||||
//this test is just to show how to initialize state
|
||||
//and verify that cargo test is actually working
|
||||
let example = StateOwner{
|
||||
state: String::from("State Owner Created!"),
|
||||
};
|
||||
let example = StateOwner::new(String::from("State Owner Created!"));
|
||||
|
||||
assert_eq!(example.state, "State Owner Created!");
|
||||
assert_eq!(example.get_state(), "State Owner Created!");
|
||||
}
|
||||
Reference in New Issue
Block a user