Replace try_set
with set_if_ok
This commit is contained in:
parent
874c823dbe
commit
894931a6e7
2 changed files with 11 additions and 10 deletions
|
@ -181,13 +181,11 @@ pub struct Regulator {
|
|||
}
|
||||
|
||||
impl Regulator {
|
||||
pub fn try_set(&self, set_pt_spec: String) -> bool {
|
||||
match SpecifiedValue::try_from(set_pt_spec) {
|
||||
Ok(set_pt) => {
|
||||
/* TO DO */
|
||||
// if it's called for, add a `set` method that takes a bare SpecifiedValue
|
||||
pub fn set_if_ok<E>(&self, set_pt_result: Result<SpecifiedValue, E>) {
|
||||
if let Ok(set_pt) = set_pt_result {
|
||||
self.set_point.set(set_pt);
|
||||
true
|
||||
}
|
||||
Err(_) => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::{
|
|||
ElementKey,
|
||||
Regulator,
|
||||
RegulatorKey,
|
||||
SpecifiedValue,
|
||||
SpecifiedValue::*
|
||||
}
|
||||
};
|
||||
|
@ -55,9 +56,11 @@ fn RegulatorInput(regulator: Regulator) -> View {
|
|||
},
|
||||
placeholder=regulator.measurement.with(|result| result.to_string()),
|
||||
bind:value=value,
|
||||
on:change=move |_| valid.set(
|
||||
regulator.try_set(value.get_clone_untracked())
|
||||
),
|
||||
on:change=move |_| {
|
||||
let set_pt_result = SpecifiedValue::try_from(value.get_clone_untracked());
|
||||
valid.set(set_pt_result.is_ok());
|
||||
regulator.set_if_ok(set_pt_result);
|
||||
},
|
||||
on:keydown={
|
||||
move |event: KeyboardEvent| {
|
||||
match event.key().as_str() {
|
||||
|
|
Loading…
Add table
Reference in a new issue