Hi,
I want to learn more about the language, and low level code.
So I have decided to implement SSH protocole following RFC.
But I have a problem...
Let's look at my code (you can get it on GitHub) :
In SshConnection struct, I have a 'write' method (I will maybe change the name), wich must send command through SSH.
So i have a TcpStream (got it from 'connect' method), and I am trying to use 'write' method on it.
Here the exemple I have found :
use std::io::prelude::*;
use std::net::TcpStream;
fn main() -> std::io::Result<()> {
let mut stream = TcpStream::connect("127.0.0.1:34254")?;
stream.write(&[1])?;
stream.read(&mut [0; 128])?;
Ok(())
} // the stream is closed here
But when i build my project, here the error I get :
error[E0599]: no method named `write` found for struct `TcpStream` in the current scope
--> src\ssh\ssh_connection.rs:46:24
|
46 | stream.write(ssh_packet.into_bytes());
| ^^^^^ method not found in `TcpStream`
|
::: C:\Users\...\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\io\mod.rs:1291:8
|
1291 | fn write(&mut self, buf: &[u8]) -> Result<usize>;
| ----- the method is available for `Box<TcpStream>` here
|
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use std::io::Write;`
It said that the method is available for Box<TcpStream>
. I have tried to put the stream into a box with Box::new(stream)
, but same error with 'the method is available for Box<Box<TcpStream>>
'.
So I am lost...
Could you help me to understand what went wrong please ?