rust-ftp icon indicating copy to clipboard operation
rust-ftp copied to clipboard

QUIT on drop

Open workanator opened this issue 8 years ago • 4 comments

Now the user should issue QUIT manually and I think that should be automated. I suggest implement Drop trait and issue quit on drop and probably make the function private.

workanator avatar Apr 08 '16 05:04 workanator

I think this would be a great improvement, but why make the quit function private? It may be a good idea to leave it around if a user wants to manually quit.

mattnenterprise avatar Apr 08 '16 15:04 mattnenterprise

If we leave it public then we should track if the user issued it already and that is one more field in FtpStream struct. But that is not really a big deal.

workanator avatar Apr 08 '16 16:04 workanator

+1 to have imp Drop for FtpStream do the QUIT. However, this is a breaking change, so if we take this road there might be other breaking changes that may be worth doing. For instance I see that the return type of simple_retr is Result<Cursor<Vec>>, I would propose that we change it to Result<Vec> (the user can create the cursor if she wants to).

matt2xu avatar Jan 11 '17 14:01 matt2xu

To add to this (perhaps a bit late), the purpose of making the quit function private is two-fold:

  1. It's consistent with other rust types in the standard library. Note the lack of a close() function on sockets or files.
  2. It prevents the user from calling quit multiple times by accident. Let the compiler handle the cleanup. The borrow checker can handle this for you.

One last option would be to decorate quit() with a:

#[deprecated(
    since = "4.0.0",
    note = "This function is now a no-op.  quit is implicitly called on drop"
)]
pub fn quit(&mut self) {}

and move the actual implementation to Drop. This would warn the users, but keep probably 90% of the existing code working.

jordanbray avatar Jan 06 '21 19:01 jordanbray