Skip to content

Commit

Permalink
fix: Added Send marker to the Closure: `dyn Fn(SocketAddr) -> Pin<B…
Browse files Browse the repository at this point in the history
…ox<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;`
  • Loading branch information
veeso committed Oct 15, 2024
1 parent d328e6c commit e12fa00
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

- [Changelog](#changelog)
- [6.0.3](#603)
- [6.0.2](#602)
- [6.0.1](#601)
- [6.0.0](#600)
Expand Down Expand Up @@ -35,6 +36,13 @@

---

## 6.0.3

Released on 15/10/2024

- Added `Send` marker to the Closure: `dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;`
- Added unit test to guarantee that FtpStream stays `Send`

## 6.0.2

Released on 14/10/2024
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["suppaftp", "suppaftp-cli"]
resolver = "2"

[workspace.package]
version = "6.0.2"
version = "6.0.3"
edition = "2021"
authors = [
"Christian Visintin <christian.visintin@veeso.dev>",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>

<p align="center">Developed by <a href="https://veeso.github.io/">veeso</a> and <a href="/~https://github.com/mattnenterprise">Matt McCoy</a></p>
<p align="center">Current version: 6.0.2 (14/10/2024)</p>
<p align="center">Current version: 6.0.3 (15/10/2024)</p>

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down
27 changes: 25 additions & 2 deletions suppaftp/src/async_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::types::Features;
///
/// It takes a [`SocketAddr`] and returns a [`TcpStream`].
pub type PassiveStreamBuilder =
dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>>;
dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;

/// Stream to interface with the FTP server. This interface is only for the command stream.
pub struct ImplAsyncFtpStream<T>
Expand Down Expand Up @@ -257,7 +257,9 @@ where
/// to create the [`TcpStream`] for the data connection in passive mode.
pub fn passive_stream_builder<F>(mut self, stream_builder: F) -> Self
where
F: Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + 'static,
F: Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>>
+ Send
+ 'static,
{
self.passive_stream_builder = Box::new(stream_builder);
self
Expand Down Expand Up @@ -1447,6 +1449,27 @@ mod test {
});
}

/// Test if the stream is Send
fn is_send<T: Send>(_send: T) {}

#[async_attributes::test]
async fn test_ftp_stream_should_be_send() {
crate::log_init();
let ftp_stream = AsyncFtpStream::connect("test.rebex.net:21")
.await
.unwrap()
.passive_stream_builder(|addr| {
Box::pin(async move {
println!("Connecting to {}", addr);
TcpStream::connect(addr)
.await
.map_err(FtpError::ConnectionError)
})
});

is_send::<AsyncFtpStream>(ftp_stream);
}

// -- test utils

#[cfg(feature = "with-containers")]
Expand Down
16 changes: 16 additions & 0 deletions suppaftp/src/sync_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,4 +1497,20 @@ mod test {
TcpStream::connect(addr).map_err(FtpError::ConnectionError)
});
}

/// Test if the stream is Send
fn is_send<T: Send>(_send: T) {}

#[test]
fn test_ftp_stream_should_be_send() {
crate::log_init();
let ftp_stream = FtpStream::connect("test.rebex.net:21")
.unwrap()
.passive_stream_builder(|addr| {
println!("Connecting to {}", addr);
TcpStream::connect(addr).map_err(FtpError::ConnectionError)
});

is_send::<FtpStream>(ftp_stream);
}
}

0 comments on commit e12fa00

Please sign in to comment.