Generalize constraints to observables #48
2 changed files with 9 additions and 13 deletions
|
|
@ -124,16 +124,6 @@ pub struct Regulator {
|
||||||
pub set_point: Signal<SpecifiedValue>
|
pub set_point: Signal<SpecifiedValue>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Regulator {
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the velocity is expressed in uniform coordinates
|
// the velocity is expressed in uniform coordinates
|
||||||
pub struct ElementMotion<'a> {
|
pub struct ElementMotion<'a> {
|
||||||
pub key: ElementKey,
|
pub key: ElementKey,
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,15 @@ fn RegulatorInput(regulator: Regulator) -> View {
|
||||||
placeholder=regulator.measurement.with(|result| result.to_string()),
|
placeholder=regulator.measurement.with(|result| result.to_string()),
|
||||||
bind:value=value,
|
bind:value=value,
|
||||||
on:change=move |_| {
|
on:change=move |_| {
|
||||||
let set_pt_result = SpecifiedValue::try_from(value.get_clone_untracked());
|
valid.set(
|
||||||
valid.set(set_pt_result.is_ok());
|
match SpecifiedValue::try_from(value.get_clone_untracked()) {
|
||||||
|
glen marked this conversation as resolved
Outdated
|
|||||||
regulator.set_if_ok(set_pt_result);
|
Ok(set_pt) => {
|
||||||
|
regulator.set_point.set(set_pt);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(_) => false
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
on:keydown={
|
on:keydown={
|
||||||
move |event: KeyboardEvent| {
|
move |event: KeyboardEvent| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue
This looks like the code is checking the OK-ness of the try_from twice. Is there a concise clear way to bind a variable to the SpecifiedValue payload in the OK return case and set
validto true and call the as-yet-unwritten regulator.set with that specified value, in that case, and in the alternative (Error) case, just setvalidto false and do nothing to the regulator? That organization would seem to read more crisply, as long as it isn't too cumbersome to write... And in fact, if I recall, isn't that sort of thing whatif let OK(blah) = try_from { ... } else {valid.set(false)}is for?P.S. If the code here switched to something like this suggestion, then as this is the only instance of
set_if_ok, you could remove that method in favor of a simplersetmethod, or in fact maybe just a direct call ofregulator.set_point.set(...), eliminating the entireimpl Regulatorblock at lines 127-135 of assembly.rs, which seems like a win.So I guess I am specifically suggesting replacing this block with
-- presuming the syntax is OK -- and just removing that
impl Regulatorblock in assembly.rs altogether.That sounds great to me. I'd reorganize the block to avoid the repetition of
valid.set. Depending on whether you preferif letormatch, we could do either of these:In the
matchversion, the argument ofvalid.setis just an inlined version of the oldRegulator::try_setmethod. If we want to go this route, and you don't have a strong preference for inlining, I'd recommend just reverting commit894931a, which replacedRegulator::try_setwithRegulator::set_if_ok. We can also rewritetry_setto useif letinstead ofmatch, of course.