I am trying to send data from the server to the client as an "OK" line:
let mut writer = BufWriter::new(&client_stream); ... let answer = String::from("OK"); let size_dat = answer.len(); let _ = writer.write(size_dat);// <------------ ошибка тут let _ = writer.write(answer.as_bytes()) writer.flush().unwrap(); // <------------ проталкивание буферизованных данных в поток and I get the error that usize is not at all byte / u8:
error[E0308]: mismatched types --> <anon>:87:42 | 87 | let _ = writer.write(size_dat); | ^^^^^^^^ expected &[u8], found usize | = note: expected type `&[u8]` = note: found type `usize` There was an idea to convert usize to byte / u8 but did not find such a function. Can somehow convert them through a vector or through a String,
let str_size = String::from(format!("{}", size_dat)); let _ = writer.write(str_size.as_bytes()); How to transfer the size of the data sent to the client?
All Code: Playground URL Gist URL