rust

How to dynamically build function calls with different numbers of arguments in Rust?

我与影子孤独终老i 提交于 2021-02-15 05:25:05
问题 How do I take a vector of function argument AST variants, extract the values, and use them to instantiate a function call? I am writing an interpreter that evaluates certain expressions. Some of the expressions are function calls. I am having a hard time figuring out how to translate the function calls AST to the actual call. The AST gives me the function name and a vector of arguments. I can lookup the function pointer to call from the name using a map, but passing the arguments to the

How can I create a Tokio runtime inside another Tokio runtime without getting the error “Cannot start a runtime from within a runtime”?

牧云@^-^@ 提交于 2021-02-15 04:50:22
问题 I'm using rust_bert for summarising text. I need to set a model with rust_bert::pipelines::summarization::SummarizationModel::new , which fetches the model from the internet. It does this asynchronously using tokio and the issue that (I think) I'm running into is that I am running the Tokio runtime within another Tokio runtime, as indicated by the error message: Downloading https://cdn.huggingface.co/facebook/bart-large-cnn/config.json to "/home/(censored)/.cache/.rustbert/bart-cnn/config

【Rust日报】2020-08-24 理解 Rust 的切片

给你一囗甜甜゛ 提交于 2021-02-14 17:25:06
理解 Rust 的切片 在迁移一些 C/C++ 代码到 Rust 过程中, 你是否也对 切片 的 所有权 如何从 Rust 中传递给 C 感到困惑 ? 亦或是对 切片 的内存布局感到困惑, 从而担心是否会造成内存泄露 ? 作者开始有同样的不解, 在深入了解以后,写下该篇文章帮助有同样疑惑的人. https://codecrash.me/understanding-rust-slices 裸金属上使用 Rust 泛型 1/2 作者通过自己的验证, 证实 Rust 在嵌入式领域中完全可以开发工业级标准的软件. 通过一个真实的例子, 如何为两个不同的闪存设备芯片来抽象一个统一读写的接口, 来介绍如何在嵌入式中使用泛型. https://www.ecorax.net/as-above-so-below-1/ IOTA Identity 现已开源 去中心化的数字身份, 又名 身份自主权 ( Self Sovereign Identity (SSI) ). IOTA identity 是一个他的一个具体实现. 他实现了 W3C 中的 DID(Decentralized Identifiers) 和 Verifiable Credentials 以及其他相关的标准. 目前该项目在积极开发中,感兴趣的同学可以时刻关注其动态. https://github.com/iotaledger

【Rust日报】2020-06-08

≡放荡痞女 提交于 2021-02-14 16:52:27
mlua v0.4 发布并支持Lua 5.4 mlua v0.4 released with Lua 5.4 support https://github.com/khvzak/mlua mlua v0.4 发布并支持Lua 5.4。 v0.4 changelog MiniCouchDB: implementing a subset of CouchDB in Rust MiniCouchDB: implementing a subset of CouchDB in Rust https://www.garrensmith.com/blogs/mini-couch-hack-week https://github.com/garrensmith/couch_hack_week 受 mini-redis 启发,搞了一个 mini-CouchDB in Rust . Benchrs: Apache Benchmark(ab) clone in rust Benchrs: Apache Benchmark(ab) clone in rust https://crates.io/crates/benchrs Apache Benchmark style http bench tool written in async rust. Benchrs 0.1.7 Arkaitz Jimenez

【Rust日报】2020-06-16

被刻印的时光 ゝ 提交于 2021-02-14 16:21:11
Rust语言实现网页分析器 A simple web analytics in Rust https://github.com/kooparse/bast Rust语言实现网页分析器,生成网站流量简明报告。 Rust和WebAssembly多线程系统库 A multithreading library for Rust and WebAssembly https://github.com/w3reality/wasm-mt A multithreading library for Rust and WebAssembly. Rust和WebAssembly多线程系统库。 用Rust语言清除Gitignored垃圾 Using Rust to Delete Gitignored Cruft https://www.forrestthewoods.com/blog/using-rust-to-delete-gitignored-cruft/ native-dialog - 跨平台文件选取器和消息框开发库 native-dialog - A cross-platform file picker and message box library. https://github.com/balthild/native-dialog-rs native-dialog显示文件选取器和消息框

用欧拉计划学习Rust编程(第13~16题)

为君一笑 提交于 2021-02-13 15:22:19
最近想学习Libra数字货币的MOVE语言,发现它是用Rust编写的,所以先补一下Rust的基础知识。学习了一段时间,发现Rust的学习曲线非常陡峭,不过仍有快速入门的办法。 学习任何一项技能最怕没有反馈,尤其是学英语、学编程的时候,一定要“用”,学习编程时有一个非常有用的网站,它就是“欧拉计划”,网址: https://projecteuler.net 这个网站提供了几百道由易到难的数学问题,你可以用任何办法去解决它,当然主要还得靠编程,编程语言不限,论坛里已经有Java、C#、Python、Lisp、Haskell等各种解法,当然如果你直接用google搜索答案就没任何乐趣了。 学习Rust最好先把基本的语法和特性看过一遍,然后就可以动手解题了,解题的过程就是学习、试错、再学习、掌握和巩固的过程,学习进度会大大加快。 第1~6题 第7~12题 第13题 大整数求和 问题描述: 有100个长达50位的大整数,求和,只取前10位数字。 各种编程语言都有大整数的函数库,直接使用就行了,不用自己造轮子。在Rust里一样也有大量的现成的库,称为crate,这个单词翻译为“柳条箱”,不知道官方的翻译是什么。大整数的官方实现是num_bigint。 需要修改Cargo.toml文件: [dependencies] num-bigint = "0.2.2" 文件头加上相关的引用: extern

How to statically assert the end of a function is unreachable

偶尔善良 提交于 2021-02-11 18:01:49
问题 I have a fairly complicated match statement (with nested if s and the like) at the end of a function. Every branch of this should either explicitly return from the function, or call some -> ! function (such as process::exit ). For both communication to other programmers, and to protect myself from myself, I'd like to tell the compiler to assert that anything after this match is unreachable. I know it knows how to do this statically, since if I put code there I get compile-time warnings. Two

How to statically assert the end of a function is unreachable

*爱你&永不变心* 提交于 2021-02-11 18:01:34
问题 I have a fairly complicated match statement (with nested if s and the like) at the end of a function. Every branch of this should either explicitly return from the function, or call some -> ! function (such as process::exit ). For both communication to other programmers, and to protect myself from myself, I'd like to tell the compiler to assert that anything after this match is unreachable. I know it knows how to do this statically, since if I put code there I get compile-time warnings. Two

“cannot borrow as mutable because it is also borrowed as immutable” with match [duplicate]

半世苍凉 提交于 2021-02-11 17:12:50
问题 This question already has an answer here : How to lookup from and insert into a HashMap efficiently? (1 answer) Closed 1 year ago . I'm attempting to count the character frequency in a string and store the count of each character in a BTreeMap . However, I'm getting a warning and would like to get rid of it. This is what I've tried: use std::collections::BTreeMap; fn letter_frequency(input: &str) -> BTreeMap<char, i32> { let mut tree: BTreeMap<char, i32> = BTreeMap::new(); for item in &input

“cannot borrow as mutable because it is also borrowed as immutable” with match [duplicate]

六眼飞鱼酱① 提交于 2021-02-11 17:05:42
问题 This question already has an answer here : How to lookup from and insert into a HashMap efficiently? (1 answer) Closed 1 year ago . I'm attempting to count the character frequency in a string and store the count of each character in a BTreeMap . However, I'm getting a warning and would like to get rid of it. This is what I've tried: use std::collections::BTreeMap; fn letter_frequency(input: &str) -> BTreeMap<char, i32> { let mut tree: BTreeMap<char, i32> = BTreeMap::new(); for item in &input