Comments (5)
@apatrushev clone your
destination
please
Thank you for the quick reply. I tried almost all imaginable variants of clone/copy/slice/etc. Nothing helps.UPD: I found the solution
(&destination[..]).to_string()
, not the simple one, but I will try to understand whats going on myself. Thank you for your help!
A simpler solution is: (notice the to_owned
)
tokio_socks::tcp::Socks5Stream::connect(proxy, destination.to_owned())
from tokio-socks.
@apatrushev Sorry, my fault. Now I've uploaded a new version to solve the problem. You can simply pass in an owned String and get a SocksStream which has 'static
lifetime.
from tokio-socks.
Unfortunately it does not help to find a solution for the code in second example. tokio-socks still claims about lifetimes:
use futures::future::{Future, IntoFuture};
use std::{
error::Error,
io::{Error as IoError, ErrorKind},
net::SocketAddr,
};
type ConnectFuture = Box<dyn Future<Item = tokio::net::TcpStream, Error = IoError> + Send>;
fn connect(address: &String) -> Result<ConnectFuture, Box<dyn Error>> {
let parts: Vec<_> = address.split("#").collect();
let (proxy, destination) = (parts[0], parts[1]);
let proxy = proxy.parse::<SocketAddr>()?;
Ok(Box::new(
tokio_socks::tcp::Socks5Stream::connect(proxy, destination)
.into_future()
.flatten()
.map(|tcp| {
println!("Connected to proxy");
tcp.into_inner()
})
.map_err(|_| IoError::new(ErrorKind::Other, "socks problem")),
))
}
fn main() {
let address = std::env::args().nth(1).unwrap();
tokio::run(connect(&address).unwrap().map(|_| ()).map_err(|_| ()));
}
Error:
Compiling tokio-socks v0.1.3 ([...]/tokio-socks)
error[E0621]: explicit lifetime required in the type of `address`
--> examples/lifetime.rs:14:5
|
10 | fn connect(address: &String) -> Result<ConnectFuture, Box<dyn Error>> {
| ------- help: add explicit lifetime `'static` to the type of `address`: `&'static std::string::String`
...
14 | / Ok(Box::new(
15 | | tokio_socks::tcp::Socks5Stream::connect(proxy, destination)
16 | | .into_future()
17 | | .flatten()
... |
22 | | .map_err(|_| IoError::new(ErrorKind::Other, "socks problem")),
23 | | ))
| |______^ lifetime `'static` required
error: aborting due to previous error
For more information about this error, try `rustc --explain E0621`.
error: Could not compile `tokio-socks`.
To learn more, run the command again with --verbose.
from tokio-socks.
@apatrushev clone your destination
please
from tokio-socks.
@apatrushev clone your
destination
please
Thank you for the quick reply. I tried almost all imaginable variants of clone/copy/slice/etc. Nothing helps.
UPD: I found the solution (&destination[..]).to_string()
, not the simple one, but I will try to understand whats going on myself. Thank you for your help!
from tokio-socks.
Related Issues (13)
- ConnectFuture buffer too small HOT 1
- TCP nodelay HOT 2
- support for unix socket HOT 2
- How to compile an executable program? HOT 1
- Update for Tokio 0.3
- Feature request: SOCKS5 UDP support
- Remove Panic for unknown auth type HOT 2
- Possible Buffer Overflow HOT 2
- Feature Request: Socks5 Gssapi support. HOT 1
- Feature Request: SOCK4 support HOT 1
- Support futures ecosystem (that is: better support for non-tokio runtimes) HOT 4
- Reading extra bytes when server returns connection error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokio-socks.