No method put() for BytesMut


#1

I’m confused one nonunderstandable thing in using BytesMut. I used bytes = "0.4.8". So here is my situation: I have lib.rs:

pub extern crate tokio_io;
pub extern crate bytes;
pub mod codec;

and module file codec.rs:

use tokio_io::codec::{Encoder, Decoder};
use bytes::{BytesMut, Bytes};
use std::io;

pub struct MyData(pub u64, pub String);
pub struct MyFrame;

impl MyFrame {
    pub fn new() -> MyFrame {
        MyFrame
    }
}

impl Encoder for MyFrame {

type Item = Bytes;
type Error = io::Error;

fn encode(
    &mut self,
    data: Self::Item,
    dst: &mut BytesMut
) -> Result<(), Self::Error> {

    dst.reserve(data.len());
    dst.put(data); // Error is here

    Ok(())
}

And in line dst.put(data); I meet error:

error[E0599]: no method named `put` found for type `&mut bytes::BytesMut` in the current scope
  --> src/codec.rs:27:13
   |
27 |         dst.put(data);
   |             ^^^
   |
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           candidate #1: `use bytes::BufMut;`

Why does it happen?


#2

The compiler told you:

   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           candidate #1: `use bytes::BufMut;`

#3

Oh, it was really easy. Thank you, @DanielKeep !!!