char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
f4a0f5b
main
1use std:: io::{ self , IoSlice }; 2use std:: pin:: Pin ; 3use std:: task::{ Context , Poll }; 4 5use tokio:: io::{ AsyncRead , AsyncWrite , ReadBuf }; 6 7pub enum Socket { 8Tcp ( tokio:: net:: TcpStream ), 9# [ cfg ( unix )] 10Unix ( tokio:: net:: UnixStream ), 11} 12 13impl From < tokio:: net:: TcpStream > for Socket { 14fn from ( socket : tokio:: net:: TcpStream ) ->Self { 15Self :: Tcp ( socket) 16} 17} 18 19# [ cfg ( unix )] 20impl From < tokio:: net:: UnixStream > for Socket { 21fn from ( socket : tokio:: net:: UnixStream ) ->Self { 22Self :: Unix ( socket) 23} 24} 25 26impl AsyncRead for Socket { 27fn poll_read ( 28self : Pin < & mut Self >, 29cx : & mut Context < ' _ >, 30buffer : & mut ReadBuf < ' _ >, 31) ->Poll < io:: Result <()>> { 32match self . get_mut () { 33Self :: Tcp ( socket) =>Pin :: new ( socket). poll_read ( cx, buffer), 34# [ cfg ( unix )] 35Self :: Unix ( socket) =>Pin :: new ( socket). poll_read ( cx, buffer), 36} 37} 38} 39 40impl AsyncWrite for Socket { 41fn poll_write ( 42self : Pin < & mut Self >, 43cx : & mut Context < ' _ >, 44buffer : & [ u8 ], 45) ->Poll < io:: Result < usize >> { 46match self . get_mut () { 47Self :: Tcp ( socket) =>Pin :: new ( socket). poll_write ( cx, buffer), 48# [ cfg ( unix )] 49Self :: Unix ( socket) =>Pin :: new ( socket). poll_write ( cx, buffer), 50} 51} 52 53fn poll_write_vectored ( 54self : Pin < & mut Self >, 55cx : & mut Context < ' _ >, 56buffers : & [ IoSlice < ' _ >], 57) ->Poll < io:: Result < usize >> { 58match self . get_mut () { 59Self :: Tcp ( socket) =>Pin :: new ( socket). poll_write_vectored ( cx, buffers), 60# [ cfg ( unix )] 61Self :: Unix ( socket) =>Pin :: new ( socket). poll_write_vectored ( cx, buffers), 62} 63} 64 65fn is_write_vectored ( & self ) ->bool { 66match self { 67Self :: Tcp ( socket) => socket. is_write_vectored (), 68# [ cfg ( unix )] 69Self :: Unix ( socket) => socket. is_write_vectored (), 70} 71} 72 73fn poll_flush ( self : Pin < & mut Self >, cx : & mut Context < ' _ >) ->Poll < io:: Result <()>> { 74match self . get_mut () { 75Self :: Tcp ( socket) =>Pin :: new ( socket). poll_flush ( cx), 76# [ cfg ( unix )] 77Self :: Unix ( socket) =>Pin :: new ( socket). poll_flush ( cx), 78} 79} 80 81fn poll_shutdown ( self : Pin < & mut Self >, cx : & mut Context < ' _ >) ->Poll < io:: Result <()>> { 82match self . get_mut () { 83Self :: Tcp ( socket) =>Pin :: new ( socket). poll_shutdown ( cx), 84# [ cfg ( unix )] 85Self :: Unix ( socket) =>Pin :: new ( socket). poll_shutdown ( cx), 86} 87} 88}