1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::blob::File;
use wasm_bindgen::prelude::*;

/// A list of files, for example from an `<input type="file">`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FileList {
    inner: Vec<File>,
}

impl From<web_sys::FileList> for FileList {
    fn from(raw: web_sys::FileList) -> Self {
        let length = raw.length();

        let inner = (0..length)
            .map(|i| File::from(raw.get(i).unwrap_throw()))
            .collect();

        FileList { inner }
    }
}

impl std::ops::Deref for FileList {
    type Target = [File];

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}