Skip to content

Commit e12fa00

Browse files
committed
fix: Added Send marker to the Closure: dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;
1 parent d328e6c commit e12fa00

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
- [Changelog](#changelog)
4+
- [6.0.3](#603)
45
- [6.0.2](#602)
56
- [6.0.1](#601)
67
- [6.0.0](#600)
@@ -35,6 +36,13 @@
3536

3637
---
3738

39+
## 6.0.3
40+
41+
Released on 15/10/2024
42+
43+
- Added `Send` marker to the Closure: `dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;`
44+
- Added unit test to guarantee that FtpStream stays `Send`
45+
3846
## 6.0.2
3947

4048
Released on 14/10/2024

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["suppaftp", "suppaftp-cli"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "6.0.2"
6+
version = "6.0.3"
77
edition = "2021"
88
authors = [
99
"Christian Visintin <[email protected]>",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</p>
1212

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

1616
<p align="center">
1717
<a href="https://opensource.org/licenses/MIT"

suppaftp/src/async_ftp/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::types::Features;
4141
///
4242
/// It takes a [`SocketAddr`] and returns a [`TcpStream`].
4343
pub type PassiveStreamBuilder =
44-
dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>>;
44+
dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = FtpResult<TcpStream>> + Send>> + Send;
4545

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

1452+
/// Test if the stream is Send
1453+
fn is_send<T: Send>(_send: T) {}
1454+
1455+
#[async_attributes::test]
1456+
async fn test_ftp_stream_should_be_send() {
1457+
crate::log_init();
1458+
let ftp_stream = AsyncFtpStream::connect("test.rebex.net:21")
1459+
.await
1460+
.unwrap()
1461+
.passive_stream_builder(|addr| {
1462+
Box::pin(async move {
1463+
println!("Connecting to {}", addr);
1464+
TcpStream::connect(addr)
1465+
.await
1466+
.map_err(FtpError::ConnectionError)
1467+
})
1468+
});
1469+
1470+
is_send::<AsyncFtpStream>(ftp_stream);
1471+
}
1472+
14501473
// -- test utils
14511474

14521475
#[cfg(feature = "with-containers")]

suppaftp/src/sync_ftp/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,4 +1497,20 @@ mod test {
14971497
TcpStream::connect(addr).map_err(FtpError::ConnectionError)
14981498
});
14991499
}
1500+
1501+
/// Test if the stream is Send
1502+
fn is_send<T: Send>(_send: T) {}
1503+
1504+
#[test]
1505+
fn test_ftp_stream_should_be_send() {
1506+
crate::log_init();
1507+
let ftp_stream = FtpStream::connect("test.rebex.net:21")
1508+
.unwrap()
1509+
.passive_stream_builder(|addr| {
1510+
println!("Connecting to {}", addr);
1511+
TcpStream::connect(addr).map_err(FtpError::ConnectionError)
1512+
});
1513+
1514+
is_send::<FtpStream>(ftp_stream);
1515+
}
15001516
}

0 commit comments

Comments
 (0)