This allows me to write a function that can accept both Event<DragData> and Event<FormData> as Event<T: HasFileData> -- without this PR, DragDatahas impl HasFileData such that I can do event.files() but while FormData can do event.files() it is because that is explicitly a part of FormData, not with an impl HasFileData so each event would need to be handled separately. Now they can be handled together.
I am tempted to remove the impl FormData ... fn files() (linked above) and let this new impl HasFileData take over, but I am nervous that this might break something somewhere. Please correct me if I am wrong and I will remove the old impl.
Sample fn for purpose:
async fn handle_upload<T: HasFileData>(
evt: Event<T>,
) {
if let Some(file_engine) = evt.files() {
for filename in file_engine.files() {
if let Some(bytes) = file_engine.read_file(&filename).await {
// ...
}
}
}
}
This allows me to write a function that can accept both
Event<DragData>
andEvent<FormData>
asEvent<T: HasFileData>
-- without this PR,DragData
hasimpl HasFileData
such that I can doevent.files()
but whileFormData
can doevent.files()
it is because that is explicitly a part ofFormData
, not with animpl HasFileData
so each event would need to be handled separately. Now they can be handled together.I am tempted to remove the
impl FormData ... fn files()
(linked above) and let this newimpl HasFileData
take over, but I am nervous that this might break something somewhere. Please correct me if I am wrong and I will remove the old impl.Sample fn for purpose: