You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
While working with Inquire to setup a name verification, I look through an HashMap that is contained by a struct and pass that struct through a ref, that looks like this :
structContainer{ids:HashMap<String,usize>,}fntype_id(container:&Container) -> InquireResult<String>{Text::new("type the id:").with_validator(|text:&str| {// Validation process...if container.ids.contains(text){Validation::Invalid("nope, exists".into())}else{Validation::Valid}}).prompt()}
But I can't pass a simple ref to the validator as it needs a static lifetime, and I rather avoid cloning the hashmap / container (they can get pretty big) or sharing them through an Rc<RefCell<T>>.
TLDR: We add a second lifetime to the Text struct which is associated to validators (and the autocompleter) and add a clone implementation that specializes on 'b: static.
The advantage of this solution is that it will keep the existing clone impl.
The main disadvantage is that it will be a breaking change as we need to add a lifetime.
Describe alternatives you've considered
Another solution we tried is specifying that validator must be 'a rather than 'static but we must specialize the Clone as 'a: static, which might be an even greater breaking change depending on the usage of the lib.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered:
Hey!
Ran across the same issue, having a 'static lifetime when wanting to validate something living in the AppState, as in my case, it's not ideal. Ended up cloning as the data is not very big.
If there's a possibility to change that to a simple lifetime it would be great!
Is your feature request related to a problem? Please describe.
While working with Inquire to setup a name verification, I look through an HashMap that is contained by a struct and pass that struct through a ref, that looks like this :
But I can't pass a simple ref to the validator as it needs a static lifetime, and I rather avoid cloning the hashmap / container (they can get pretty big) or sharing them through an
Rc<RefCell<T>>
.Describe the solution you'd like
I tried to implement a solution which is available on my fork : stormshield-hf@2a07dc4 (branch in case I end up doing other changes : https://github.com/stormshield-hf/inquire/tree/work/hf/remove_static_lifetimes)
TLDR: We add a second lifetime to the
Text
struct which is associated to validators (and the autocompleter) and add a clone implementation that specializes on'b: static
.The advantage of this solution is that it will keep the existing clone impl.
The main disadvantage is that it will be a breaking change as we need to add a lifetime.
Describe alternatives you've considered
Another solution we tried is specifying that validator must be
'a
rather than'static
but we must specialize theClone
as'a: static
, which might be an even greater breaking change depending on the usage of the lib.Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: