You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have many structs and enums that need to be Codable, among others. Right now, what I do is I have mirror types named FFI* and funcs for conversion:
// shared.swift// Note that we don't yet support `indirect` for enums.// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.publicenumFfiReviewUpvoteStatus{case upvote
case neutral
case downvote
}// otherCode.swiftenumReviewUpvoteStatus:Hashable,Codable{case upvote, downvote, neutral
init(ffi:FfiReviewUpvoteStatus){self= switch ffi {case.upvote:Self.upvote
case.downvote:Self.downvote
case.neutral:Self.neutral
}}}
Automatic synthesis got you covered when they are there on initialization, but if you somewhere else write an extension to conform
// otherCode.swiftextensionFfiReviewUpvoteStatus:Codable{}// Extension outside of file declaring enum 'FfiReviewUpvoteStatus' prevents automatic synthesis of 'encode(to:)' for protocol 'Encodable'
It doesn't go so well. Implementing these manually inside an extension is forbidingly difficult. One potential thing I considered is just finding and replacing the output swift but come on ;) Maybe some sort of macro like
I have many structs and enums that need to be
Codable
, among others. Right now, what I do is I have mirror types namedFFI*
and funcs for conversion:Automatic synthesis got you covered when they are there on initialization, but if you somewhere else write an extension to conform
It doesn't go so well. Implementing these manually inside an extension is forbidingly difficult. One potential thing I considered is just finding and replacing the output swift but come on ;) Maybe some sort of macro like
akin to serde?
Edit: it might also just be possible to add Codable to everything. Worth looking into if that incurs an expense.
The text was updated successfully, but these errors were encountered: