Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the index of element that was matched by exp_any #14

Open
pbartyik opened this issue Mar 22, 2020 · 4 comments
Open

get the index of element that was matched by exp_any #14

pbartyik opened this issue Mar 22, 2020 · 4 comments

Comments

@pbartyik
Copy link
Contributor

find fn returns a tuple with the unread buffer and the matched string by needle. The question is if it could also return the position of the expression used in ReadUntil::Any(vec)? Right now I'm looping through the passed expressions and checking which one matches the returned matched string.

Think "did I match username or password prompt, what to send back to the process".

@philippkeller
Copy link
Collaborator

I think this is a good idea.
But it would need to split up find for the ReadUntil variants without ReadUntil::Any (as this extra return doesn't make sense in this context) and a find for the ReadUntil::Any explicitly.

Do you have anything in mind? I didn't use rust lately so I don't know if there's any construct which could help here or if the best way forward would be just to create a separate function which would just be for ::Any and would support the new parameter

@pbartyik
Copy link
Contributor Author

honestly I'm still in the beginning of the learning curve of rust, so I may not be the best input for this.
Not sure if a hacky solution would be to return an Option as the third element in the tuple, but that would save the need for a separate function.
The separate fn seems more reasonable as that won't mess up the return values and keeps the feature explicit.

@TyPR124 what do you think? You are working on windows support, and this might affect you too.

@TyPR124
Copy link
Contributor

TyPR124 commented Mar 22, 2020

To be honest I haven't been looking closely at this part of the code, as I've been focusing mostly on the platform-specific parts and this code is mostly platform-agnostic. That said, I will give it some thought, as it sounds like a good idea.

To make sure I'm on the same page here, you're wanting to do something like session.exp_any(my_vec) and have it return an index into my_vec, correct?

@pbartyik
Copy link
Contributor Author

pbartyik commented Mar 22, 2020

Yep, along with the unread buffer till the match. The matched string have no benefit to me personally, but since it is currently returned I imagine it would be needed too.

philippkeller added a commit that referenced this issue Jun 14, 2020
draft of a possible solution to the #14 issue and changes in public interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants