rust - 为什么 js_sys::Atomics 操作需要 i32 类型的值?
问题描述
我正在尝试SharedArrayBuffer
在生锈中使用。我想在 sab 的一部分中累积 n 个工人的输出。我发现我被限制为 int 数组类型,但我的数据存储为浮点数。我正在使用Atomics::add(&rc2, idx as u32, k)
where k 是我的浮点数转换为 i32。我在所描述的每种方法中都收到了一些垃圾(当我试图从填充的 sab 中读取 float32 视图时)。我尝试过:1)to_ne_bytes + i32::from_be_bytes
在我的浮动上使用,然后将其重新组装为 i32 2)使用std::mem::transmute::<f32, i32>(v);
3)使用 to_bits / cast to u32 / from_bits / cast to i32 4)在 js sys github repo 中查找实现(此处为https:// /github.com/rustwasm/wasm-bindgen/blob/master/crates/js-sys/src/lib.rs),但似乎只有一些与外部代码的绑定,我不明白这段代码的位置,所以我可以检查为什么 Atomic add 需要 i32 以及它对它的作用。谢谢!
解决方案
推荐阅读
- python - 无法从 Python 中的本地文件导入类
- php - 如何使用简码在 WordPress 帖子中运行 mysql 查询而不将其发送到页脚
- c++ - 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- python - from google.oauth2 import service_account ModuleNotFoundError: No module named 'google'
- javascript - 如何将 JS 应用程序与文件 PHP 连接 - 找不到 php 文件
- python - python中的关键字究竟是如何工作的
- mongodb - 由于 Invariant failure rs.get() src/mongo/db/catalog/database.cpp,MongoDB 修复失败
- python - 元素点击拦截硒进行自动化
- rust - UDP 服务器示例如何安全?
- python - 将带有二进制列的 pandas 数据帧转换为更紧凑的表示