-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check that every combination of event::Name and event::Version correspond to single Rust type (#1) #3
Conversation
FCM
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv please, add also some examples with Initial<_>
in #[derive(Event)]
. It seems that we haven't covered this situation, which may result to be quite tricky one.
Quite tricky one, indeed. As we discussed, we want to express, that some state can be // Compiles just fine
#[derive(Event)]
enum ChatEvent {
Created(Init<ChatCreated>),
MessagePosted(ChatMessagePosted),
}
// Failed to compile, as we forgot the `Init<...>` wrapper
#[derive(Event)]
enum ChatEvent {
Created(ChatCreated),
MessagePosted(ChatMessagePosted),
} Proposal
pub trait Initial {
fn name() -> Name;
fn version() -> Version;
}
impl<Ev: Initial + ?Sized> Event for Init<Ev> {
fn name(&self) -> Name {
Ev::name()
}
fn version(&self) -> Version {
Ev::version()
}
}
// ⌄ wrong
impl<Ev: Event + ?Sized, S: Sourced<Ev>> Sourced<Ev> for Option<S> {
fn apply(&mut self, event: &Ev) {
if let Some(state) = self {
state.apply(event);
}
}
} If we want to store // ⌄ was `Event`, became `Versioned`
impl<Ev: Versioned + ?Sized, S: Sourced<Ev>> Sourced<Ev> for Option<S> {
fn apply(&mut self, event: &Ev) {
if let Some(state) = self {
state.apply(event);
}
}
} And add new blanket impl<Ev: Initial + ?Sized, S: Initialized<Ev>> Sourced<Init<Ev>> for Option<S> {
fn apply(&mut self, event: &Initial<Ev>) {
*self = Some(S::init(&event.0));
}
}
Main idea of those changes is to separate ack @tyranron |
@ilslv I don't see why se should introduce an additional trait/macro to handle the case. It should be possible with current setup by either specializing over |
Discussed: we don't try to derive |
eabd582
to
7701281
Compare
core/src/es/event.rs
Outdated
/// | ||
/// [`Borrow`]: std::borrow::Borrow | ||
#[sealed] | ||
pub trait BorrowInitial<Borrowed: ?Sized> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having Borrowed
as an associated type here will aid type inference a little bit better.
Part of #1, #2
Synopsis
As discussed we should check that every combination of
event::Name
andevent::Version
correspond to singleRust
type.Solution
As
TypeId::of()
isconst fn
yet (tracking issue), we use codegen location to uniquely identifyRust
type.Checklist
Draft:
prefixk::
labels appliedDraft:
prefix is removed