Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Might have found a solution #20

Open
bvssvni opened this Issue Sep 8, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@bvssvni
Copy link
Member

bvssvni commented Sep 8, 2016

The following code gives good error messages for a single back-end, and infers the types within same family:

struct VertexBuffer;
struct Texture;

trait Member { type Family; }
trait Resource<T> {}

struct Gl;
struct GlVertexBuffer;
struct GlTexture;

impl Member for GlVertexBuffer { type Family = Gl; }
impl Member for GlTexture { type Family = Gl; }

impl Resource<GlVertexBuffer> for VertexBuffer {}
impl Resource<GlTexture> for Texture {}

trait VB: Member {
    fn say_hello(&mut self);
}

impl VB for GlVertexBuffer {
    fn say_hello(&mut self) {
        println!("hello");
    }
}

fn foo<Vb, Tx>(vb: &mut Vb, _tx: Tx)
    where VertexBuffer: Resource<Vb>,
          Texture: Resource<Tx>,
          Vb: VB,
          Tx: Member<Family = Vb::Family>,
{
    vb.say_hello();
}

fn main() {
    foo(&mut GlVertexBuffer, GlTexture);
}

play.rust-lang.org

@bvssvni bvssvni added the discussion label Sep 8, 2016

@bvssvni

This comment has been minimized.

Copy link
Member Author

bvssvni commented Sep 8, 2016

This idea was taken from the discrete library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.