我正在尝试访问通过输入字段上传的文件内容的迭代器。
我可以通过 web-sys 将 JS 文件传递到 Wasm 中,但我一生都无法弄清楚如何访问 Rust 中传递的文件的长度和名称之外的任何内容。
我想我可以将整个文件作为 ByteArray 传递到 Wasm 中并对其进行迭代,但最好我想直接迭代文件内容而不进行复制,因为文件本身会很大(~1 GB)。
我在 Mozilla JS 文档中发现,我应该能够访问底层文件 blob,通过该.stream()方法从中获取 ReadableStream,并从中获取应该能够迭代的 Reader。但在 web-sys 中,.getReader()ReadableStream 的方法返回一个简单的 JSValue,我无法用它做任何有用的事情。
我是否在这里遗漏了一些东西,或者这个功能只是在网络系统中丢失了,还是有其他方法可以做到这一点?也许在 JS 中创建迭代器并将其传递给 Rust?
我不知道如何修复此错误(对于 Windows 上的 pip install Transformer):\n错误:找不到 Rust 编译器
\nIf you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.\n\nTo update pip, run:\n\n pip install --upgrade pip\n\nand then retry package installation.\n\nIf you did intend to build this package from source, try installing a Rust compiler from your system package manager and …Run Code Online (Sandbox Code Playgroud) 我使用包含项目的货物工作区。当我跑步时
cargo build
Run Code Online (Sandbox Code Playgroud)
它从工作区根目录构建所有项目成员(如果我错了,请纠正我)。
然后,当我想从我使用的工作区构建特定项目时
cargo build -p my_project_1
Run Code Online (Sandbox Code Playgroud)
看起来它开始构建 my_project_1 依赖项。尽管所有依赖项都应该在第一 cargo build 阶段构建。
如何使用第一阶段完成的依赖项构建缓存?
使用 Apache Arrow 格式将数据从 Node.js 传递到 Rust 的最佳方法是什么?用每种语言存储数据很容易,但共享内存给我带来了挑战。
我正在使用Napi-rs生成 node.js API 绑定。
对于下面的 JavaScript 代码,我收到“无法从缓冲区创建引用”的消息。当我尝试传递arrowVector.data[0].buffers给 rust 函数时,我得到 "../src/node_buffer.cc:245:char *node::Buffer::Data(Local<v8::Value>): Assertion `val->IsArrayBufferView() ' 失败的。”
我想我在这里缺少一些核心内容。
这是我的示例节点测试代码:
import { makeVector } from 'apache-arrow';
import {testFn} from './index.js';
// Create arrow Vec
const LENGTH = 2000;
const rainAmounts = Float32Array.from(
{ length: LENGTH },
() => Number((Math.random() * 20).toFixed(1)));
const arrowVector = makeVector(rainAmounts);
// how to get buffers from vec? and send to rust function
testFn(arrowVector);
Run Code Online (Sandbox Code Playgroud)
这是我的 Rust 代码示例: …
macro_rules! foo {
( $( $( $tok:tt )* ,)* ) => {
[ bar!( $( $tok )* ,)* ]
}
}
Run Code Online (Sandbox Code Playgroud)
产生错误:local ambiguity when calling macro 'foo'. 因为逗号','的类型是:tt。我需要一种方法来匹配除逗号标记之外的所有标记树。
foo!(
add t0 zero zero,
add t1 t0 a0,
lb t1 0(t1),
)
Run Code Online (Sandbox Code Playgroud)
应产生:
[
bar!(add t0 zero zero),
bar!(add t1 t0 a0),
bar!(lb t1 0(t1)),
]
Run Code Online (Sandbox Code Playgroud) 我最近发现了windows-rs框架,并一直在寻求通过实现其ICredentialProvider COM 接口来在 Rust 中构建Windows 凭据提供程序。
我一直在使用现有问题之一中汇总的信息进行概念验证实现,但我不确定如何实际将编译后的 Rust 公开为正确的 DLL,然后向 Windows 系统注册。
use std::cell::RefCell;
use windows::{
core::implement,
Win32::UI::Shell::{ICredentialProvider, ICredentialProvider_Impl},
};
fn main() -> windows::core::Result<()> {
#[implement(ICredentialProvider)]
struct Provider {
mutable_state: RefCell<u32>,
}
impl Provider {
fn new() -> Self {
Self {
mutable_state: RefCell::new(0),
}
}
}
impl ICredentialProvider_Impl for Provider {
fn Advise(
&self,
pcpe: &core::option::Option<windows::Win32::UI::Shell::ICredentialProviderEvents>,
upadvisecontext: usize,
) -> windows::core::Result<()> {
*self.mutable_state.borrow_mut() = 42;
todo!();
}
fn GetCredentialAt(
&self,
dwindex: u32,
) …Run Code Online (Sandbox Code Playgroud) 在 Serde 序列化器中,如何添加附加字段:
#[derive(Serialize)]
struct X {
a: u32,
b: u32,
c: u32,
}
Run Code Online (Sandbox Code Playgroud)
我想添加到 JSON 序列化字段dvalue "qwe"。X如何不从头开始完全编写序列化器?
我使用的是srx crate,它在 Rust 1.61 下工作正常。现在,我更新到 Rust 1.70,但它找不到FromStr特征实现。
在 1.61 中有效但在 1.70 中无效的示例代码:
use std::fs::read_to_string;
use std::fs;
use std::str::FromStr;
use srx::SRX;
fn main() {
let srx_file = "../data/language_tool.segment.srx";
let _srx2: SRX = read_to_string(srx_file).expect("").parse().unwrap();
let _srx1 = SRX::from_str(&fs::read_to_string(srx_file).unwrap())?;
}
Run Code Online (Sandbox Code Playgroud)
和编译器错误:
error[E0277]: the trait bound `SRX: FromStr` is not satisfied
--> src/main.rs:8:58
|
8 | let _srx2: SRX = read_to_string(srx_file).expect("").parse().unwrap();
| ^^^^^ the trait `FromStr` is not implemented for `SRX`
|
= help: the following other types implement trait `FromStr`: …Run Code Online (Sandbox Code Playgroud) 我正在 Haskell 库中寻找如下所示的类(或者至少知道此类事物的数学名称):
class Monoid patch => MyThing patch t where
applyPatch :: t -> patch -> t
Run Code Online (Sandbox Code Playgroud)
我可以有这样的实例:
instance MyThing (Last t) t where
applyPatch x patch = case getLast patch of
Just y => y
Nothing => x
Run Code Online (Sandbox Code Playgroud)
但我也可以有这样的实例:
instance MyThing (Dual (Map key value)) (Map key value) where
applyPatch x patch = ...
Run Code Online (Sandbox Code Playgroud)
补丁本质上是添加和/或替换映射中的键/值对。
如果你想删除,可以更进一步:
instance MyThing (Dual (Map key (Maybe value))) (Map key value) where
applyPatch x patch = ...
Run Code Online (Sandbox Code Playgroud)
除了patch成为幺半群之外,我希望此类遵循的主要法则是结合性,具体来说:
forall (x :: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试制作一个功能类似于Python输入函数的宏。
而不是每次我想要稍微自动化它时都完全编写标准输入,并结合 println!这样我就可以用一块石头杀死两只鸟。
本质上,如果有人传入一个参数,它会打印一个字符串,然后要求输入,如果他们不这样做,它只会要求从终端输入。
#[macro_export]
macro_rules! input {
($a:expr) => {
println!("{}", $a);
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
return $input
};
(_) => {
let mut input = String::new();
std::io::stdin().read_line(&mut $input).unwrap();
return $input
};
}
Run Code Online (Sandbox Code Playgroud)
我在 let 语句上不断收到错误,只是不知道如何继续,因为我不太了解宏语法。
我发布了整个代码块,因为在第二个匹配表达式上,我试图在没有参数的情况下进行匹配,但我不确定我是否做得正确。
有时错误消息将我带到 github 页面,并且遇到随机错误,所以我只是困惑如何继续进一步
如果有人能帮助我修复 let 语句,我将不胜感激,对于给您带来的任何不便,我深表歉意。
rust ×9
macros ×2
windows ×2
apache-arrow ×1
com ×1
haskell ×1
input ×1
macro-rules ×1
monoids ×1
node.js ×1
rust-arrow2 ×1
rust-cargo ×1
rust-macros ×1
semigroup ×1
serde ×1
syntax ×1
traits ×1
wasm-bindgen ×1
webassembly ×1
windows-credential-provider ×1
windows-rs ×1