Closed Vulpesx closed 4 months ago
I had an idea while writing this, that you should be able to update the spinner while it's running (probably through a mspc) so you could show new info in the spinner as your code progresses. I'll make another pr for that, unless you want it in this one. Also, if you want me to split the changes in this into different pr's I can.
wonderful changes! thank you!
👍🏼 can only second that, great contribution!
I found
Spinner.run
andDemandOption
to be overly restrictive in functionality that made it rather annoying to useRestrictive trait bounds
firstly,
DemandOption
requiringitem
to be display is rather ridiculous, after all it's the label that gets displayed even if the label is taken from the item.So the item doesn't require display now, the
new fn
does the same thing it did before (making the label from the item) but it requiresToString
instead because while before it required Display you were actually usingToString
which you could do sinceToString
is impl on allimpl Display
. RequiringToString
is more accurate and allows types that implToString
but notDisplay
Since
new
still requires item to beToString
we need another fn that allows us to take advantage of item not needingDisplay
anymore. That's whatDemandOption::with_label
does, it takes a separate label and item, the label beingInto<String>
and item being justT
. There is also.item
fn to be consistent with the rest of the lib.Select
andMultiSelect
do not requireDisplay
either. For some reason,Select
was usingitem.to_string
instead of the label to render, which is the only placeToString
and by extensionDisplay
was ever needed foritem
.Scoped threads
the old
Spinner.run
required a static Fn which means the Fn can only move or take static references which is really annoying especially since It's clearly not necessary since run will not return unless the thread is done. Thankfully, rust has scoped threads which remove this limitation. As a bonus I changedrun
to take aFnOnce
which is more appropriate as it's only run once, and it allows for more closure magic, as well as haverun
return the value theFnOnce
returns. If the thread running theFnOnce
panicsrun
will return anio::Error
with the kind beingOther
(which exists precisely for when you need to return any error as anio::Error
) with the value being the panic message.Just to be clear. None of the changes in this pr affect any code already using demand. You can just do more now