rust

rust初学记录-excel导出

佐手、 提交于 2021-01-18 14:03:29
尝试使用 rocket 导出excel文件 。 使用 toolchain 是 stable-x86_64-pc-windows-gnu Cargo.toml [package] name = "test_rust_exportexcel" version = "0.0.1" authors = ["xx <xx@163.com>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # toolchain :stable-x86_64-pc-windows-gnu [dependencies] rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "c24f15c18f02319be83af4f3c1951dc220b52c5e" } simple_excel_writer = "0.1.7" uuid = { version = "0.8", features = ["serde", "v4"] } [dependencies.tokio] version = "1.0" features = ["fs", "io

WebAssembly

爷,独闯天下 提交于 2021-01-17 20:43:32
WebAssembly From Wikipedia, the free encyclopedia Jump to navigation Jump to search WebAssembly Paradigm Imperative , structured , expression-oriented Designed by W3C Developer W3C Mozilla Microsoft Google Apple First appeared March 2017 ; 3 years ago Typing discipline Static License Apache License 2.0 Filename extensions .wat .wasm Website webassembly.org Influenced by asm.js PNaCl WebAssembly (often shortened to Wasm ) is an open standard that defines a portable binary-code format for executable programs , and a corresponding textual assembly language , as well as interfaces for facilitating

聊一聊构建的抽象

天涯浪子 提交于 2021-01-16 08:40:49
最近,在研究 Gradle 和 Java 相关构建的实现,让我对不同编程语言的应用构建燃起了一点点的兴趣。 不同编程语言编写的应用,在它运行的状态下,会有不同的运行机制,有的是以二进制的方式运行的,有运行在编程语言的虚拟机之上。而构建所做的事情呢,就是将那些我们写给人类看的代码,转换为机器/程序能看懂的代码。所以,构建的本质就是翻译(~~复读机~~)。 PS:本文旨在尝试性的整理我所了解的构建知识。部分内容限于对某一些编程语言的理解有限,并非非常准确。如有偏颇之此,希望大家指正。 引子 1:从 Java 的编译说起 绝大多数程序员都是从 hello, world! 开始自己复制、粘贴的人生生涯。对于那些刚上手 Java 的程序员也是类似的: javac HelloWorld.java 而当我们依赖于其它的软件包时,就需要在编译时和运行时加入 classpath 来加入依赖项。于是,对应的运行命令就如下所示: java -classpath .:libs/joda-time-2.10.6.jar HelloWorld 这样,我们就能得到预期的结果了: Hello, World Millisecond time: in.getMillis(): 1599284014762 而如果我们需要打成 jar 包就需要一个复杂一点的过程: jar cvfm hello.jar manifest

Why is “one type is more general than the other” in an Option containing a closure?

邮差的信 提交于 2021-01-14 13:39:22
问题 I wrote some code that compiled fine, then I turned T into Option<T> and now I'm getting this error: error[E0308]: mismatched type...one type is more general than the other When building a minimal case I noticed that if I change data: &str into data: String the code compiles fine again. Playground link pub trait Subscriber { fn recv(&mut self, data: &str); } pub struct Task<T>(pub Option<T>) where T: Fn(&str); impl<T> Subscriber for Task<T> where T: Fn(&str), { fn recv(&mut self, data: &str)

Why is “one type is more general than the other” in an Option containing a closure?

一笑奈何 提交于 2021-01-14 13:39:04
问题 I wrote some code that compiled fine, then I turned T into Option<T> and now I'm getting this error: error[E0308]: mismatched type...one type is more general than the other When building a minimal case I noticed that if I change data: &str into data: String the code compiles fine again. Playground link pub trait Subscriber { fn recv(&mut self, data: &str); } pub struct Task<T>(pub Option<T>) where T: Fn(&str); impl<T> Subscriber for Task<T> where T: Fn(&str), { fn recv(&mut self, data: &str)

Why is “one type is more general than the other” in an Option containing a closure?

谁都会走 提交于 2021-01-14 13:36:31
问题 I wrote some code that compiled fine, then I turned T into Option<T> and now I'm getting this error: error[E0308]: mismatched type...one type is more general than the other When building a minimal case I noticed that if I change data: &str into data: String the code compiles fine again. Playground link pub trait Subscriber { fn recv(&mut self, data: &str); } pub struct Task<T>(pub Option<T>) where T: Fn(&str); impl<T> Subscriber for Task<T> where T: Fn(&str), { fn recv(&mut self, data: &str)

Rust mpsc::Sender cannot be shared between threads?

半腔热情 提交于 2021-01-13 09:21:48
问题 I thought the whole purpose of a channel was to share data between threads. I have this code, based on this example: let tx_thread = tx.clone(); let ctx = self; thread::spawn(|| { ... let result = ctx.method() tx_thread.send((String::from(result), someOtherString)).unwrap(); }) Where tx is a mpsc::Sender<(String, String)> error[E0277]: the trait bound `std::sync::mpsc::Sender<(std::string::String, std::string::String)>: std::marker::Sync` is not satisfied --> src/my_module/my_file.rs:137:9 |

Rust mpsc::Sender cannot be shared between threads?

。_饼干妹妹 提交于 2021-01-13 09:19:17
问题 I thought the whole purpose of a channel was to share data between threads. I have this code, based on this example: let tx_thread = tx.clone(); let ctx = self; thread::spawn(|| { ... let result = ctx.method() tx_thread.send((String::from(result), someOtherString)).unwrap(); }) Where tx is a mpsc::Sender<(String, String)> error[E0277]: the trait bound `std::sync::mpsc::Sender<(std::string::String, std::string::String)>: std::marker::Sync` is not satisfied --> src/my_module/my_file.rs:137:9 |

Flask 之父:我不觉得有异步压力

主宰稳场 提交于 2021-01-12 02:50:34
英文 | I'm not feeling the async pressure 原作 | Armin Ronacher,2020.01.01 译者 | 豌豆花下猫@Python猫 声明 :本翻译基于CC BY-NC-SA 4.0授权协议,内容略有改动,转载请保留原文出处,请勿用于商业或非法用途。 异步(async)正风靡一时。异步Python、异步Rust、go、node、.NET,任选一个你最爱的语言生态,它都在使用着一些异步。异步这东西有多好,这在很大程度上取决于语言的生态及其运行时间,但总体而言,它有一些不错的好处。它使得这种事情变得非常简单:等待可能需要一些时间才能完成的操作。 它是如此简单,以至于创造了无数新的方法来坑人(blow ones foot off)。我想讨论的一种情况是,直到系统出现超载,你才意识到自己踩到了脚的那一种,这就是背压(back pressure)管理的主题。在协议设计中有一个相关术语是流量控制(flow control)。 什么是背压 关于背压的解释有很多,我推荐阅读的一个很好的解释是:Backpressure explained — the resisted flow of data through software【3】。因此,与其详细介绍什么是背压,我只想对其做一个非常简短的定义和解释:背压是阻碍数据在系统中流通的阻力。背压听起来很负面—

Cannot infer correct lifetime when borrowing index of slice and field of a struct at once

南楼画角 提交于 2021-01-07 03:52:22
问题 I'm implementing a double buffer in Rust, so when I get the current buffer, it does self.buffers[self.index] . For the sake of brevity, I made that into a function so I could call it like this: pub struct Screen<'a> { pub canvas: Canvas<'a>, pub buffers: [Vec<u32>; 2], pub index: usize, } impl<'a> Screen<'a> { #[inline(always)] pub fn get_buf<'b>(&'a self) -> &[u32] { self.buffers[self.index].as_slice() } #[inline(always)] pub fn get_mut_buf<'b>(&mut self) -> &mut [u32] { self.buffers[self