rust

Temporary value dropped while borrowed, but I don't want to do a let

橙三吉。 提交于 2020-12-21 02:42:13
问题 I'm doing something like this: fn main() { //[1, 0, 0, 0, 99]; // return [2, 0, 0, 0, 99] //[2, 3, 0, 3, 99]; // return [2,3,0,6,99] //[2, 4, 4, 5, 99, 0]; // return [2,4,4,5,99,9801] //[1, 1, 1, 4, 99, 5, 6, 0, 99]; // return [30,1,1,4,2,5,6,0,99] let map: Vec<(&mut [usize], &[usize])> = vec![(&mut [1, 0, 0, 0, 99], &[2, 0, 0, 0, 99])]; for (x, y) in map { execute_program(x); assert_eq!(x, y); } } pub fn execute_program(vec: &mut [usize]) { //do something inside vec } Here the playground The

【Rust日报】2020-11-11 -「InfluxDB IOx」未来会用 Rust 和 Arrow 构建内核

那年仲夏 提交于 2020-12-20 06:18:08
「InfluxDB IOx」未来会用 Rust 和 Arrow 构建内核 Rust提供了对运行时行为和内存管理的更精细控制。另外,它使并发编程更容易,并且消除了数据争用。 Apache Arrow定义了用于列式数据的内存格式,以及Parquet(一种持久的持久性格式)以及Flight(一种用于“通过网络接口进行大型数据集的高性能传输”的客户端/服务器框架和协议)。另外,Rust的Apache Arrow工具集中还有DataFusion,它是用于Apache Arrow的Rust本机SQL查询引擎。假设我们以DataFusion为核心进行构建,这意味着InfluxDB IOx将 支持现成的SQL子集 随着DataFusion项目的成熟,通过InfluxData外部的协作者的开发工作,它既可以在InfluxDB IOx中使用,也可以在其他地方使用。 该项目仍处于初期阶段。我们目前尚未生成构建,并且除了 InfluxDB IOx项目README 之外,没有任何文档。该团队是一个由高级工程师组成的小型小组,我们的工作与平台上其余部分的大型工程组织的所有工作并行。我们的目标是在明年初生产开源构建,并在InfluxDB Cloud中以alpha形式提供。 详情 : https://www.influxdata.com/blog/announcing-influxdb-iox/ [linux

战火重燃、奖金加码,TiDB Hackathon 2020 有你才精彩

守給你的承諾、 提交于 2020-12-16 12:09:52
TiDB Hackathon 是由 TiDB 社区主办,专属于全球开发者与技术爱好者的顶级挑战赛事,通过开发与应用实战,鼓励开发者基于 TiDB 及上下游生态项目实现技术与商业创新。 自 2017 年创办以来,TiDB Hackathon 在过去的三年连获好评,吸引了全球 800+ 技术爱好者参与,先后诞生了 Unified Threat Pool、TiDB-wasm、TiDB 跨数据中心解决方案等一些列高质量项目,已经成为全球数据库技术领域的知名赛事。 本届大赛主题为「∞」,参赛项目可围绕 TiDB 组件或结合 TiDB 生态周边(包括:TiKV、ChaosMesh®、Backup & Restore(BR)、TiDB Data Migration(DM)、Dashboard、Flink、ES 等上下游社区、用户&企业业务场景等)进行创作,用最硬核的技术和最炸裂的创意去创造无限可能。 赛事亮点 奖金加码: 除了金额丰厚的一二三等奖,本次大赛还将联合赞助商推出特别奖,以及增设最佳人气奖,欢迎小伙伴们围观 Demo 现场投出你心中最佳的项目。 全球联动: 去年北上广三地联动 Demo 的场景还历历在目,今年 TiDB 将更进一步,联动全球开发者共享代码狂欢。 项目落地: 通过 TOC(Technical Oversight Committee) 投票表决的优秀项目将在大赛结束后进入

How to return a reference to a nested Rust struct in WebAssembly?

大兔子大兔子 提交于 2020-12-16 04:09:32
问题 I have 2 structs where I can access the Parent struct from JavaScript and create it with new : struct Child { foo: String, } impl Child { pub fn do_something(&self) { /* some stuff */ } } #[wasm_bindgen] pub struct Parent { child: Child, } #[wasm_bindgen] impl Parent { pub fn new() -> Self { Self { child: Child { foo: String::new() }, } } pub fn child(&self) -> &Child { &self.child } } I cannot compile the code because of an error at the child() method: cannot return a borrowed ref with #

EEPROM和FLASH,NAND FLASH和NOR FLASH有什么区别?

偶尔善良 提交于 2020-12-15 19:06:54
存储器分为两大类:RAM和ROM,RAM就不讲了,主要讨论ROM。 ROM最初是不能编程的,出厂什么内容就永远什么内容,不灵活。 后来出现了PROM,可以自己写入一次,要是写错了,只能换一片,自认倒霉。人类文明不断进步,终于出现了可多次擦除写入的EPROM,每次擦除要把芯片拿到紫外线上照一下,想一下你往单片机上下了一个程序之后发现有个地方需要加一句话,为此你要把单片机放紫外灯下照半小时,然后才能再下一次,这么折腾一天也改不了几次。 历史的车轮不断前进,伟大的EEPROM出现了,拯救了一大批程序员,终于可以随意的修改ROM中的内容了。 EEPROM的全称是“电可擦除可编程只读存储器”,即Electrically Erasable Programmable Read-Only Memory。是相对于紫外擦除的ROM来讲的。但是今天已经存在多种EEPROM的变种,变成了一类存储器的统称。 狭义的EEPROM: 这种ROM的特点是可以随机访问和修改任何一个字节,可以往每个bit中写入0或者1。这是最传统的一种EEPROM,掉电后数据不丢失,可以保存100年,可以擦写100w次。具有较高的可靠性,但是电路复杂/成本也高。因此目前的EEPROM都是几十千字节到几百千字节的,绝少有超过512K的。 例如我们常见的24C02: 广义的EEPROM: FLASH属于广义的EEPROM

How to pattern match a Box to get a struct's attribute?

南楼画角 提交于 2020-12-15 06:49:04
问题 I'm trying to access an attribute of a boxed struct inside an enum but I can't figure out how to pattern-match with std::boxed::Box enum ArithExp { Sum { lhs: Box<ArithExp>, rhs: Box<ArithExp>, }, Mul { lhs: Box<ArithExp>, rhs: Box<ArithExp>, }, Num { value: f64, }, } fn num(value: f64) -> std::boxed::Box<ArithExp> { Box::new(ArithExp::Num { value }) } let mut number = num(1.0); match number { ArithExp::Num { value } => println!("VALUE = {}", value), } I get the following error: error[E0308]:

Rust trait issues trait cannot be made into an object

拥有回忆 提交于 2020-12-15 04:32:06
问题 I'm familiar with rust but i suck with traits so forgive me for my ignorance. So Im trying to write some code that will generate a random struct with a random value. have the following trait and helper macros for the structs use rand::{thread_rng, Rng}; use std::fmt; pub trait DataType { /// generate a new instance of the type with a random value fn random() -> Box<Self>; /// generate a new instance of the same type with a random value fn gen_another(&self) -> Box<Self>; } macro_rules! impl

Rust trait issues trait cannot be made into an object

纵然是瞬间 提交于 2020-12-15 04:31:50
问题 I'm familiar with rust but i suck with traits so forgive me for my ignorance. So Im trying to write some code that will generate a random struct with a random value. have the following trait and helper macros for the structs use rand::{thread_rng, Rng}; use std::fmt; pub trait DataType { /// generate a new instance of the type with a random value fn random() -> Box<Self>; /// generate a new instance of the same type with a random value fn gen_another(&self) -> Box<Self>; } macro_rules! impl

How can you iterate and change the values in a mutable array in Rust?

喜欢而已 提交于 2020-12-15 02:00:29
问题 This is how far I got: #[derive(Copy, Clone, Debug)] enum Suits { Hearts, Spades, Clubs, Diamonds, } #[derive(Copy, Clone, Debug)] struct Card { card_num: u8, card_suit: Suits, } fn generate_deck() { let deck: [Option<Card>; 52] = [None; 52]; for mut i in deck.iter() { i = &Some(Card { card_num: 1, card_suit: Suits::Hearts, }); } for i in deck.iter() { println!("{:?}", i); } } fn main() { generate_deck(); } It only prints out None . Is there something wrong with my borrowing? What am I doing

How can you iterate and change the values in a mutable array in Rust?

≯℡__Kan透↙ 提交于 2020-12-15 01:56:27
问题 This is how far I got: #[derive(Copy, Clone, Debug)] enum Suits { Hearts, Spades, Clubs, Diamonds, } #[derive(Copy, Clone, Debug)] struct Card { card_num: u8, card_suit: Suits, } fn generate_deck() { let deck: [Option<Card>; 52] = [None; 52]; for mut i in deck.iter() { i = &Some(Card { card_num: 1, card_suit: Suits::Hearts, }); } for i in deck.iter() { println!("{:?}", i); } } fn main() { generate_deck(); } It only prints out None . Is there something wrong with my borrowing? What am I doing