在 rust 中从 web_sys::File 获取参数
Get parameters from web_sys::File in rust
我正在从 JavaScript 发送一个 FileList 并尝试从列表中读取特定文件的参数,例如文件名,但我收到错误:method not found in Option<web_sys::File>
(我'已尝试不同的变体来调用 web-sys doc 中定义的文件的 getter 方法,但没有成功)。
#[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"
]
files.get(1)
returns Option<File>
which could be either None
or Some(File)
variant。您可以使用 match
语句来匹配这些变体并采取相应的措施。
#[wasm_bindgen]
pub fn get_file_list_detail(files : web_sys::FileList) -> Option<web_sys::File> {
let first_file = files.get(1);
match first_file {
Some(ref file) => {
log!("Test console log from rust {:?}=",file.name());
},
None => {
log!("file is Missing")
}
}
return first_file;
}
我正在从 JavaScript 发送一个 FileList 并尝试从列表中读取特定文件的参数,例如文件名,但我收到错误:method not found in Option<web_sys::File>
(我'已尝试不同的变体来调用 web-sys doc 中定义的文件的 getter 方法,但没有成功)。
#[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"
]
files.get(1)
returns Option<File>
which could be either None
or Some(File)
variant。您可以使用 match
语句来匹配这些变体并采取相应的措施。
#[wasm_bindgen]
pub fn get_file_list_detail(files : web_sys::FileList) -> Option<web_sys::File> {
let first_file = files.get(1);
match first_file {
Some(ref file) => {
log!("Test console log from rust {:?}=",file.name());
},
None => {
log!("file is Missing")
}
}
return first_file;
}