Open ActuallyHappening opened 2 months ago
That does sound nice to have!
We can also have a more general
fn with_command(self, f: impl FnOnce(&mut Self)) -> Self;
I would accept a PR for this.
@NobodyXu I am checking out the codebase and have some basic understanding. The suggestion seems like a interesting addition of API. If were to implement the function signature you suggested, based on my understanding that would be an addition of something like
// in src/session.rs, I presumed?
// presuming Self == openssh::Session?
pub fn with_command(self, f: impl FnOnce(&mut Self)) -> Self { todo!() }
Could you give a concrete example of what would be an instance of function/closure as the argument of the type: f: impl FnOnce(&mut Self)
to call the new API with?
I just started playing with the codebase and don't see what such instance would be like (presumably a block of code involving use of some of the existing APIs to do some business, but I just don't visualise how that might be the case)
@mingmamma the function will be added to openssh::OwningCommand
, which has many functions taking a mutable reference, such as arg
, stdin
, stdout
.
This features exists in bossy::Command here: https://docs.rs/bossy/latest/bossy/struct.Command.html#method.with_args
It is quite useful, allowing you to write this:
... instead of this:
This saves using the
mut
keyword and a new line, and can even be implemented trivially using an extension trait