Some minor fixes.

This commit is contained in:
Daniel Mowitz 2021-05-01 15:57:40 +02:00
parent fea845a533
commit 10c85a9584

View file

@ -40,13 +40,13 @@ impl<S: Read + Write> IrcRead for IrcStream<S> {
let mut message: Option<Message> = None;
while message == None {
let mut temp_buf = [0; 512];
self.stream.read(&mut temp_buf);
self.stream.read(&mut temp_buf)?;
self.buffer.push_str(std::str::from_utf8(&temp_buf)?);
match self.buffer.find("\r\n") {
Some(i) => {
let mut raw_message = self.buffer.clone();
// This returns the part after the line break to the buffer.
self.buffer = raw_message.split_off(i);
self.buffer = raw_message.split_off(i+2);
message = Some(Message::from(raw_message.as_str()));
},
None => (),
@ -71,7 +71,7 @@ impl<S: Read + Write> IrcWrite for IrcStream<S> {
}
impl<S: Read + Write> IrcStream<S> {
fn new(stream: S) -> Self {
pub fn new(stream: S) -> Self {
Self{
stream,
buffer: String::new()