Skip to content

Difficulty creating a wrapper type #400

Closed
@nickeb96

Description

@nickeb96

This is more of a question than a bug, but I'm trying to get the following simplified example to work:

struct LuaVec<'lua>(pub Vec<Value<'lua>>);

impl<'lua> UserData for LuaVec<'lua> {
  fn add_methods<'lua2, M: UserDataMethods<'lua2, Self>>(methods: &mut M) {
    methods.add_method_mut("push", |_, this, value: Value<'lua2>| {
      this.0.push(value);
      Ok(())
    });
  }
}

I've tried a few different variations of having one lifetime depend on the other, but everything I've tried gives me error[E0276]: impl has stricter requirements than trait.

Is it possible with the current userdata api to implement UserData on a type that already has lua values in it? I realize that the two lifetimes need to be the same, but I can't figure out how to represent that and still implement the trait properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions