socks_lib/
lib.rs

1pub mod socks5;
2
3use std::future::Future;
4use std::io::Result;
5
6use bytes::BytesMut;
7use tokio::io::{AsyncReadExt, AsyncWriteExt};
8
9#[rustfmt::skip]
10pub mod consts {
11    pub const PORT_LENGTH:          usize = 2;
12    pub const IPV4_ADDRESS_LENGTH:  usize = 4;
13    pub const IPV6_ADDRESS_LENGTH:  usize = 16;
14}
15
16pub trait Streamable {
17    fn write<T>(&self, stream: &mut T) -> impl Future<Output = Result<()>> + Send
18    where
19        Self: ToBytes + Send + Sync,
20        T: AsyncWriteExt + Unpin + Send,
21    {
22        async move { stream.write_all(&self.to_bytes()).await }
23    }
24
25    fn read<T>(stream: &mut T) -> impl Future<Output = Result<Self>> + Send
26    where
27        Self: Sized,
28        T: AsyncReadExt + Unpin + Send;
29}
30
31pub trait ToBytes {
32    fn to_bytes(&self) -> BytesMut;
33}