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
DerefMut is prone to footguns, it's dangerous to push people to use it. The way we use it is also not a primary use-case as a rust language feature, so we are likely to create poor rust compilation error messages.
So maybe we should swap to traits for this
How would it look like?
So, the idea is to:
For each Dsl, implement methods only as members of a trait:
pubstructMyDsl<T:DslBundle = ()>{inner:T,zoobi:Zoob,bashoung:Bob,}pubtraitMyDslTrait{typeInner;fnfrom_my_dsl(&mutself) -> &mutMyDsl<Self::Inner>;fnzoobi(&mutself,zoobi:Zoobi){self.from_my_dsl().zoobi = zoobi;}// etc. all methods call `from_my_dsl` and have such default implementation.}impl<T:DslBundle>MyDslTraitforMyDsl<T>{typeInner = T;fnfrom_my_dsl(&mutself) -> &mutSelf{self}// The rest is already implemented by default.}
If we make a macro to derive DslBundle, the very same macro should be able to create and export such a trait.
Now, we can also implement foreign DSLs with this (imagining a ForeignDsl struct and a ForeignDslTrait following the same pattern):
And now we are back to providing access to methods across all dsls combined into one type.
However, the downside here is that we need to explicitly import all the relevant traits and add those nosiy impl blocks (though they are relatively small)
Ideally, we get rid of the boilerplate with a macro, the downside is that now we are relying on macros for a lot more than before.
The text was updated successfully, but these errors were encountered:
DerefMut
is prone to footguns, it's dangerous to push people to use it. The way we use it is also not a primary use-case as a rust language feature, so we are likely to create poor rust compilation error messages.So maybe we should swap to
trait
s for thisHow would it look like?
So, the idea is to:
For each
Dsl
, implement methods only as members of a trait:If we make a macro to derive
DslBundle
, the very same macro should be able to create and export such a trait.Now, we can also implement foreign DSLs with this (imagining a
ForeignDsl
struct and aForeignDslTrait
following the same pattern):And now we are back to providing access to methods across all dsls combined into one type.
However, the downside here is that we need to explicitly import all the relevant traits and add those nosiy
impl
blocks (though they are relatively small)Ideally, we get rid of the boilerplate with a macro, the downside is that now we are relying on macros for a lot more than before.
The text was updated successfully, but these errors were encountered: