Open pbartyik opened 4 years ago
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
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
@TyPR124 what do you think? You are working on windows support, and this might affect you too.
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?
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.
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".