Stream: general

Topic: Using multiple implementations of the same interface


view this post on Zulip Robbe Haegeman (Sep 26 2025 at 13:28):

Hey!

I'm currently developing a tic-tac-toe toy project using a MVC-esque architecture.
The goal would be that the user resource from the user-interface could have 2 implementations, for example 'real-player' and 'bot', which both can be used in the game component.
The goal would be to have a similar system to having 2 different structs in Rust, implement the same trait.
The main issue I'm facing is that in order to instantiate 2 different implementations, these would both have to be composed into the final artifact and thus would have to be differentiated.

sketch of both current and desired setup

The ideal API for this use-case would be that I want to express that there are multiple implementations available for the same interface, but this goes against the current system.
My current attempts try to create wrappers (worlds and interfaces which's only goal is to re-export the capabilities of the user), which are purely WIT files, but I haven't gotten it to work yet.

What would be the proper approach for tackling this problem?

view this post on Zulip Alex Crichton (Sep 26 2025 at 19:51):

More-or-less this is unfortunately not supported at this time. You can only export or import one version of an interface, which means that this pattern is not well supported.

You're not the first person to desire this, however, and it's something we'd like to support! I don't believe there's many tracking issues on this but effectively what you want is "nested interfaces" in WIT where you could do something like:

world my-world {
  interface player1: { nest my:player/interface-definition; }
  interface player2: { nest my:player/interface-definition; }
}

(bikeshedding notwithstanding)

view this post on Zulip Till Schneidereit (Sep 29 2025 at 10:38):

There's an open PR for nested interfaces. Not sure what @Daniel Macovei's plans are around this, though

Here is an outline for the various ways in which one could describe nested interfaces in wit. For additional context re: motivation, see this issue, though generally what this enables is the abilit...

view this post on Zulip Daniel Macovei (Sep 30 2025 at 14:35):

I could put effort into reviving this PR if there were renewed interest in it. I think resolving dependencies from registries would benefit from it. At the moment though, I kindof figured it would make more sense to revisit after wasi p3 ships

view this post on Zulip Till Schneidereit (Oct 01 2025 at 12:53):

yeah, I don't disagree with the order of things. However, with work on p3 winding down on the spec and tooling side, it might make sense to look into again


Last updated: Dec 06 2025 at 05:03 UTC