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
The design for some modules (like charted_search) would want a trait with methods that accept generic types, but generic types aren't object-safe, so what do we do to keep it easy and maintainable?
use charted_search::SearchService;// some options to use to modify the request bodypubstructOptions{}// a service that extends `SearchService`pubstructMyService{}implSearchServiceforMyService{typeOptions = Options;fnindex(){/* do some indexing */}fnsearch(){/* do some search */}}
Even though hacks do exist where we would have to use an enum to differentiate without getting the dreaded we cannot turn this object-safe as we would want to use generics for:
Index Name: Into<String>
Index Type: serde::DeserializedOwned/serde::Serialize
I'm wondering if there is any way we could do this where we can keep a dyn SearchService without doing more enum hacks and making it harder to maintain multiple objects that implement a trait that require dynamic dispatch.
I was thinking of doing a "hacky vtable" but I'm not too sure if we can do:
structVtable{do_index:unsafefn(a:implTrait<Of,Some,Sorts>) -> /* result */,}
and calling it since Rust treats fn as a function pointer rather than a type (like Fn, which function pointers do implement!) and only generate what implementation of the Trait<T, U, V> is used, and it is a design chosen by the Rust language, and I think we need to think for now on how to keep this maintainable without dreading hacky solutions.
Using enums and generating an implementation of that is still too hacky for me since it's more code that is only there to patch existing designs by Rust.
The text was updated successfully, but these errors were encountered:
The design for some modules (like
charted_search
) would want a trait with methods that accept generic types, but generic types aren't object-safe, so what do we do to keep it easy and maintainable?Even though hacks do exist where we would have to use an enum to differentiate without getting the dreaded
we cannot turn this object-safe
as we would want to use generics for:Into<String>
serde::DeserializedOwned
/serde::Serialize
I'm wondering if there is any way we could do this where we can keep a
dyn SearchService
without doing more enum hacks and making it harder to maintain multiple objects that implement a trait that require dynamic dispatch.I was thinking of doing a "hacky vtable" but I'm not too sure if we can do:
and calling it since Rust treats
fn
as a function pointer rather than a type (likeFn
, which function pointers do implement!) and only generate what implementation of theTrait<T, U, V>
is used, and it is a design chosen by the Rust language, and I think we need to think for now on how to keep this maintainable without dreading hacky solutions.Using enums and generating an implementation of that is still too hacky for me since it's more code that is only there to patch existing designs by Rust.
The text was updated successfully, but these errors were encountered: