veeso / suppaftp

a super FTP/FTPS client library for Rust with support for both passive and active mode
Apache License 2.0
112 stars 28 forks source link

[Feature Request] - Better composability #60

Open JohnScience opened 11 months ago

JohnScience commented 11 months ago

Description

As I was working on a commercial project using suppaftp, I faced various challenges:

Thanks to your crate, I was spared from a lot of work, so I thank you for that. However, the library right now is fairly low level and does not offer many conveniences that one could expect.

For now, my biggest annoyance is the ImplFtpStream::list method, which probably shouldn't have existed in this form.

When implementing an iterator over remote entries, I have to deal with a Vec<Vec<Result<MyCustomDirEntryType, MyCustomWrapperAroundParseError>>.

And due to the nature of the iterator, I ended up facing the limitations of the NLL borrow checker (https://github.com/danielhenrymantilla/polonius-the-crab.rs/issues/11) and I had to deal with the absence of entry API on vector until the pain became so severe that I ended up implementing entry API for Vec as a stack (link).

Without your library, I would have to write FTP client code myself, so again, thank you.

Changes

The most important changes are the following:

JohnScience commented 11 months ago

Regarding Drop, I realize that it's fallible, so it could be your motivation. However, presenting a way to do that with reasonable defaults would be awesome. If you want to have a fallible drop in Rust, you can consider sharing your opinion/thoughts in https://internals.rust-lang.org/t/idea-fallible-drop-attribute-for-let-statements/19680.

veeso commented 11 months ago

That's a very interesting feedback. I will check every point to see if it's feasible.

JohnScience commented 11 months ago

@veeso

I seem to have managed to come up with an idea on how to write an iterator despite the limitations of the pre-Polonius NLL borrow checker: https://github.com/JohnScience/list_iter.

Note: it is implemented for MockFtpClient, which requires fds instead of paths. Managing paths adds only a little bit of complexity. Dealing with Results adds moderate amount of complexity.