- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在玩 wasm-bindgen
( https://github.com/rustwasm/wasm-bindgen ),只是出于好奇。
一边玩Navigator
( web_sys
crate) 我偶然发现了这个方法:
https://docs.rs/web-sys/0.3.36/web_sys/struct.MediaDevices.html#method.enumerate_devices
它返回一个 Result<Promise, JsValue>
..现在,我是 Rust 的新手,我的问题是如何获取 Promise
的值?Closure::wrap
怎么了作品?
如何使用 then获取结果的方法?
我想知道是否有人可以这么好心地向我解释如何处理Promise
这是一个返回 Promise
的示例:
let window = web_sys::window().expect("no global `window` exists");
let navigator = window.navigator();
if let Ok(devs) = navigator.media_devices() {
if let Ok(prom) = devs.enumerate_devices() {
//..??? how to list all devices
}
}
最佳答案
有official documentation available on the wasm-bindgen site .
总之,您可以使用 wasm_bindgen_futures::JsFuture::from(promise).await?
检索 promise 的结果并继续使用通常的 Rust async
功能。
关于promise - Rust/Webassembly/wasm-bindgen - 从 `js_sys' Promise 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60786667/
所以我有一个头库(.h 文件的目录),我需要在我的 rust 代码中使用它。为了让这个工作,我一直在寻找各种 crate 来帮助我实现这个,看起来 bindgen 是最有希望的选择。 我遵循了 bin
我正在尝试使用 bindgen 生成与 Qt6 的绑定(bind)。我关注了this回答并尝试了这个: - let bindings = bindgen::Builder::default()
我有一个从WASM-Bindgen "canvas" example派生的Rust程序。我试图在onmousemove元素的每个JavaScript Canvas事件上调用一些Rust代码。我的代码当
我正在为 a small C library 编写一个 Rust 接口(interface),它的标题分布在几个位置。它不是系统库,通常由同一包中的某些可执行文件使用;我目前将它作为一个 git 子模
根据 https://rust-lang.github.io/rust-bindgen/tutorial-3.html 上的 Rust bindgen 教程,我正在尝试为现有的 C 头文件生成 FFI
我正在尝试为 SEAL C++ library 编译绑定(bind).这是 my repo . // Generate the bindings let bindings = bindgen::Bui
虽然我确定我做错了什么,但我似乎找不到它。我正在使用 bindgen = "0.55.1"并试图生成 pjsip绑定(bind),尽管问题似乎早在那之前。这是构建的输出: error: failed
关于如何在 rust -> wasm 中使用现有 javascript Web 系统的文档使用 wasm-bindgen 的流程非常简单。简而言之: 将所需功能列为依赖项 // cargo.toml
代码是基本的,我正在用lib.rs中声明的字符串输入从js调用函数 但是字符串没有传递给wasm中的函数,我收到一个空字符串,而反向操作也不起作用,我也无法将字符串从wasm传递给js。 wasm文件
我在 Rust 中为 C 库和 Bindgen 生成的枚举创建绑定(bind),例如: // Rust #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash
我正在尝试将 FFI 指针类型发送到另一个线程。它指向的结构已由 bindgen 生成 from opensles-sys 这是我的包装器结构: pub struct AndroidAudioIO {
有没有人设法编译rust-bindgen在 Ubuntu 14.04 上?例如,我不知道如何静态构建和链接到 libclang.so。我每晚使用 rust-nightly。 最佳答案 下面只设置可执行
我在 rust-bindgen 的帮助下为 C 库编写绑定(bind),函数签名自动生成到 bindings.rs 中,如下所示: #[repr(C)] struct A { //... }
我正在尝试编写一个在浏览器中运行的简单游戏,但考虑到浏览器、rust 和 wasm-bindgen 强加的限制,我很难为游戏循环建模。 浏览器中的典型游戏循环遵循以下一般模式: function ma
我正在尝试使用 Rust 的 Web3 JavaScript 库,但我被卡住了。该库的标准用法从以下内容开始: // In Node.js use: const Web3 = require('web
我有一个 Vec我想返回并使用 wasm-bindgen 转换为类型化数组,即转换 Vec进入 Uint32Array .从我的研究来看,wasm-bindgen 似乎无法立即自动处理它们本身的转换(
我正在尝试完成 Kaleidoscope Rust 教程。 但我似乎对 codegen 感到震惊。 我的 build.rs : extern crate bindgen; use std::env;
我使用 Microsoft SEAL C++ Library 工具生成了到 rust-bindgen 的绑定(bind)。 我的配置: // Generate the bindings let bin
嵌套的 Vec 似乎无法与 wasm-bindgen 一起工作。对吗? 我的目标是在 Rust 中创建一个生命游戏网格,我可以将其作为行返回,而不是需要 JavaScript 处理索引的 1D Vec
可以像这样传递一个整数数组: const js = import("./webassembly_rust"); let array_nums = [1,2,3,4,5,6,7,8,9]; js.the
我是一名优秀的程序员,十分优秀!