Let #[Enum]
interfaces have methods
#1470
Labels
good first issue
Good for newcomers to get started with development
#[Enum]
interfaces have methods
#1470
One thing that I've found super helpful when working with enums with associated data is being able to define getters and predicates on them. Here's an example inspired by mozilla/application-services#5346 (comment):
I'd love to be able to define methods on
Suggestion
like:SuggestionDetails details()
, a getter that extracts the details from each variant.boolean is_sponsored()
, a predicate that checks the suggestion type and returns whether it's sponsored (Shopping
) or not (Education
,Wikipedia
,Weather
).UniFFI doesn't allow doing that yet, but @mhammond's follow-up comment (mozilla/application-services#5346 (comment)) inspired me to file a ticket to see if it could! 😊 As a workaround, we can add extensions in hand-written Kotlin and Swift files, but I wonder if we could push this down into UniFFI.
(It would be even nicer to make these
readonly attribute
s instead of methods—I think all our target languages support that? Python has@property
, Kotlin has getters, Swift has computed properties, Ruby's getters are regular methods—but that might be too tricky).┆Issue is synchronized with this Jira Task
┆Issue Number: UNIFFI-236
The text was updated successfully, but these errors were encountered: