|
|
Log in / Subscribe / Register

How does this compare to "Accept interfaces, return structs" in Go?

How does this compare to "Accept interfaces, return structs" in Go?

Posted May 20, 2024 23:31 UTC (Mon) by riking (subscriber, #95706)
In reply to: How does this compare to "Accept interfaces, return structs" in Go? by davecb
Parent article: Existential types in Rust

This is basically the same as returning a private struct in Go, except you're forced to specify the interface it implements, and the caller is filtered to just that interface. The caller can't downcast it to discover other interfaces it has (unless you include std::any::Any in the interface).

Rust doesn't allow you to return private structs (except via the public-in-private trick, the Go equivalent would be mypkg/internal.SomeType - you can't name the type but you can call all its methods), which is why this work is needed.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds