dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

impl HasFileData for FormData

Open rogusdev opened this issue 1 year ago • 0 comments

This allows me to write a function that can accept both Event<DragData> and Event<FormData> as Event<T: HasFileData> -- without this PR, DragData has 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 {
                // ...
            }
        }
    }
}

rogusdev avatar Apr 19 '24 18:04 rogusdev