Cocoon Crate - Method lost when passing Structs

This is the rust code
I know dump is missing some args but it isnot recognized by rust at all!
Why is this? And What is the solution?

fn test<M>(container :&mut Cocoon<'_, M>) -> (){
  container.dump();
  
}
fn main() {
  let mut container = Cocoon::new("passw".as_bytes());
  test(&mut container);
}

And then I get this

error[E0599]: no method named `dump` found for mutable reference `&mut Cocoon<'_, M>` in the current scope                              
--> src/main.rs:21:13
   |
21 |   container.dump();
   |             ^^^^ method not found in `&mut Cocoon<'_, M>`

That's because Cocoon<'_, M> does not implement dump. Cocoon<'_, Creation> on the other hand does. A generic M is not specific enough, M must be Creation in order for Cocoon to implement the dump method.

You can amend your function like this:

use cocoon::{Cocoon, Creation};

fn test(container: &mut Cocoon<'_, Creation>) {
    container.dump(b"data".to_vec(), &mut vec![]).unwrap();
}

to make it compile.

2 Likes