I'm currently learning Rust and especially traits....
# arrow
c
I'm currently learning Rust and especially traits. I've read KEEP-87 as well as the contextual receivers one previously, and I've seen mentioned multiple times that they will allow to implement an interface for a class we don't control. I understand how KEEP-87 and Rust's traits manage this, but how do context receivers enable this?
r
Hi @CLOVIS, Context receivers emulate injection by exposing the extension syntax in the function body but you still need to call
with
or
run
at some point to materialize their scope. They replace implicit summoning by making the contextual function only resolvable when they are scoped in the intersection of all declared context types.
Copy code
context(A, B)
fun foo(): Unit {}

a.run { b.run { foo() }} //ok
foo() //not ok, kotlin won't summon providers for A and B, wants you to be explicit
For the missing part we are working in the Arrow Context plugin with Arrow Meta https://github.com/arrow-kt/arrow-meta/blob/8c727799308956d28f38c4e3706bc2ce5c4a52[…]plugin/src/test/kotlin/arrow/meta/plugins/proofs/ContextTest.kt which will also work for materializing contexts from multiple receivers
c
Oh, so with context receivers it will be possible to have multiple implementations of a ‘trait’ for a single class