从 Rust 中的 web_sys::File 获取参数
我正在从 JavaScript 发送 FileList 并尝试从列表中读取特定文件的参数(例如文件名),但收到错误:在 Option
#[wasm_bindgen]
pub fn get_file_list_detail(files : web_sys::FileList) -> Option<web_sys::File> {
let first_file = files.get(1);
log!("Test console log from rust {:?}=",first_file.name()); //this is not working
return first_file;
}
我在 Cargo.toml 中添加了 File
和 FileList
:
[dependencies.web-sys]
version = "0.3"
features = [
"HtmlInputElement",
"FileList",
"File",
"console"
]
I'm sending a FileList from JavaScript and trying to read the parameters of the specific file from the list, like the file name but I'm getting the error:method not found in Option<web_sys::File>
(I'have tried different variants to call the getter methods of the File like defined in the web-sys doc but no success).
#[wasm_bindgen]
pub fn get_file_list_detail(files : web_sys::FileList) -> Option<web_sys::File> {
let first_file = files.get(1);
log!("Test console log from rust {:?}=",first_file.name()); //this is not working
return first_file;
}
I added the File
and FileList
in Cargo.toml:
[dependencies.web-sys]
version = "0.3"
features = [
"HtmlInputElement",
"FileList",
"File",
"console"
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
files.get(1)< /code>
返回
Option
,它可以是无
或某些(文件)
变体。您可以使用match
语句来匹配这些变体并采取相应的操作。files.get(1)
returnsOption<File>
which could be eitherNone
orSome(File)
variant. You can usematch
statement to match these variants and take actions accordingly.