Crates.io | zoon |
lib.rs | zoon |
version | 0.1.6 |
source | src |
created_at | 2022-11-04 01:53:08.491749 |
updated_at | 2022-11-16 21:56:26.45312 |
description | Flexible,Predictable State Management |
homepage | |
repository | https://gitlab.com/andrew_ryan/zoon |
max_upload_size | |
id | 704749 |
size | 12,333 |
Include state in your Cargo.toml [dependencies]:
[dependencies]
zoon = "0.1.6"
use zoon::State;
let state = State::new();
assert!(state.get().is_none());
assert_eq!(state.set(92), Ok(()));
assert!(state.get().is_some());
use zoon::State;
let state = State::new();
let value = state.get_or_init(|| 92);
assert_eq!(value, &92);
let value = state.get_or_init(|| unreachable!());
assert_eq!(value, &92);
use zoon::State;
let state = State::new();
assert_eq!(state.get_or_try_init(|| Err(())), Err(()));
assert!(state.get().is_none());
let value = state.get_or_try_init(|| -> Result<i32, ()> {
Ok(92)
});
assert_eq!(value, Ok(&92));
assert_eq!(state.get(), Some(&92))
use zoon::State;
let state: State<String> = State::new();
assert_eq!(state.into_inner(), None);
let state = State::new();
state.set("hello".to_string()).unwrap();
assert_eq!(state.into_inner(), Some("hello".to_string()));
use zoon::State;
let mut state: State<String> = State::new();
assert_eq!(state.take(), None);
let mut state = State::new();
state.set("hello".to_string()).unwrap();
assert_eq!(state.take(), Some("hello".to_string()));
assert_eq!(state.get(), None);