So now we need to work on allowing us to send messages.
So we're going to need to implement the function that we already called here called send JSON that our
client and server are both going to use.
So with client and server using the function, we are going to place it inside our utils file.
So let's head over to our utils file and let's start adding in a couple of more use statements that
we're going to need.
So we have async standard.
We want to add in everything in the prelude, we want to use serialize and then we want to use standard
marker.
UN pin.
So the function we are going to create is going to create a JSON representation of our packet as a string.
Then we will add a new line to the end of the string and write it all to leaving.
So let's begin to set that up so that you all can see what I'm talking about.
So we're going to say send JSON, we're going to have two generics O and P.
So we're going to say leaving, which is going to be a mutable reference to our generic and then we're
going to have a packet.
Which is a reference to our p generic and we're returning a chat result.
So we have a generico and p and now we can define define a couple of constraints on it.
So we will need a where clause.
So up here we will say where oh is async standard?
I.
Right.
And unpin.
And then p implements serialize.
So let's cargo format that to make it look better.
And there we go.
So now we have our oh generic which must implement right and on pen and then our p generic which is
must implement serialize.
So now we can turn our packet to a string and then write it to our leaving.
So we'll say let mutable JSON equals say or de json to string and do that with our.
Packet and then we want to push in our new line character, as I said earlier.
And now we're going to ride it to leaving.
Right.
All JSON as bytes.
Dot.
Wait.
And now we want to.
Return.
Okay, so now we have our logic implemented for sending messages.
So let's begin on working to receive these messages.