rust

How do I annotate the type of an empty slice in Rust?

余生颓废 提交于 2020-08-07 07:54:06
问题 Suppose I want to compare a Vec<String> to a literal empty list in a test. (I'm aware that in practice I could check is_empty() , but I'd like to understand how Rust typing works here, and I think asserting equality will give a clearer message if it fails.) If I just say let a: Vec<String> = Vec::new(); assert_eq!(a, []); I get an error that error[E0282]: type annotations needed --> src/main.rs:3:5 | 3 | assert_eq!(a, []); | ^^^^^^^^^^^^^^^^^^ cannot infer type | = note: this error originates

Does a '&&x' pattern match cause x to be copied?

余生长醉 提交于 2020-08-07 05:38:46
问题 In the documentation for std::iter::Iterator::filter() it explains that values are passed to the closure by reference, and since many iterators produce references, in that case the values passed are references to references. It offers some advice to improve ergonomics, by using a &x pattern to remove one level of indirection, or a &&x pattern to remove two levels of indirection. However, I've found that this second pattern does not compile if the item being iterated does not implement Copy :

Does a '&&x' pattern match cause x to be copied?

萝らか妹 提交于 2020-08-07 05:34:42
问题 In the documentation for std::iter::Iterator::filter() it explains that values are passed to the closure by reference, and since many iterators produce references, in that case the values passed are references to references. It offers some advice to improve ergonomics, by using a &x pattern to remove one level of indirection, or a &&x pattern to remove two levels of indirection. However, I've found that this second pattern does not compile if the item being iterated does not implement Copy :

Are there any HashMap implementations with consistent ordering between program runs?

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-07 04:58:21
问题 I've observed that HashMap has a different order of elements even with the same data on the next program start. It looks like HashMap uses some absolute addresses to sort elements. Is there any other HashMap implementation, which has the same behaviour if the same data was inserted? 回答1: I believe linked-hash-map is the de facto crate for this. 回答2: I've observed that HashMap has a different order of elements even with the same data on the next program start. You don't have to observe

Are there any HashMap implementations with consistent ordering between program runs?

孤人 提交于 2020-08-07 04:56:54
问题 I've observed that HashMap has a different order of elements even with the same data on the next program start. It looks like HashMap uses some absolute addresses to sort elements. Is there any other HashMap implementation, which has the same behaviour if the same data was inserted? 回答1: I believe linked-hash-map is the de facto crate for this. 回答2: I've observed that HashMap has a different order of elements even with the same data on the next program start. You don't have to observe

Are there any HashMap implementations with consistent ordering between program runs?

匆匆过客 提交于 2020-08-07 04:56:14
问题 I've observed that HashMap has a different order of elements even with the same data on the next program start. It looks like HashMap uses some absolute addresses to sort elements. Is there any other HashMap implementation, which has the same behaviour if the same data was inserted? 回答1: I believe linked-hash-map is the de facto crate for this. 回答2: I've observed that HashMap has a different order of elements even with the same data on the next program start. You don't have to observe

How can I create a file and its parent directories using a single method in Rust?

旧城冷巷雨未停 提交于 2020-08-07 02:38:28
问题 Can I open a file creating it and its parent directories using OpenOptions or a similar single method? This only creates a new file, it does not work if my path includes non-existing directories: pub fn save_file(file_path: String) -> Result<(), Error> { let mut db_file = OpenOptions::new() .create(true) .append(true) .open(file_path)?; db_file.write_all(b"some content")?; Ok(()) } 回答1: I couldn't find a single method to do this, but here's how to create the parent directory (etc.) for a

How can I create a file and its parent directories using a single method in Rust?

心不动则不痛 提交于 2020-08-07 02:37:21
问题 Can I open a file creating it and its parent directories using OpenOptions or a similar single method? This only creates a new file, it does not work if my path includes non-existing directories: pub fn save_file(file_path: String) -> Result<(), Error> { let mut db_file = OpenOptions::new() .create(true) .append(true) .open(file_path)?; db_file.write_all(b"some content")?; Ok(()) } 回答1: I couldn't find a single method to do this, but here's how to create the parent directory (etc.) for a

基于数据库的代码自动生成工具,生成JavaBean、生成数据库文档、生成前后端代码等(v6.9.0版)

家住魔仙堡 提交于 2020-08-06 13:37:29
TableGo_20200520 v6.9.0 正式版发布,此次版本更新如下: 1、新增对JDK9及以上版本Java环境的支持 2、生成JavaBean更名为生成数据模型并且提供了C#、C++、Golang、Rust、Python、Objective-C、Swift等编程语言数据模型的简单模板 3、新增生成SpringBoot项目工程的功能,在生成自定义文件界面直接生成一个可以跑起来的项目 4、新增对数据库视图的支持 5、新增大量自定义模板示例 6、新增SQL查询导出数据功能,在生成自定义文件时通过配置SQL查询数据导出生成任何需要的文件 7、新增一些内置静态对象用于生成自定义文件时使用,例如:org.apache.commons.lang.StringUtils 8、移除是否目录直通,如果文件保存路径设置了目录则生成的内容将直接生成到该目录下(生成自定义文件无效) 9、移除代码中生成的版本推广信息 10、生成自定义文件功能增强,添加更多可配置的参数 11、修复生成数据库文档中有中文错误的问题 12、优化对MySQL8.x的支持,现在可以使用MySQL8的新驱动包了 13、优化界面显示效果并让所有界面都能用鼠标拖动改变大小 14、优化参数配置管理功能,使全局参数配置可以保存界面上配置好的参数 15、使用JDK8编译,并使用了JDK8的新特性,不再支持JDK7 16

Rust:mod、crate、super、self、pub use等模块系统用法梳理

删除回忆录丶 提交于 2020-08-06 07:55:05
在Rust模块系统中,有诸多的概念和用法,不容易搞清楚,理一下,很有必要。 cargo是从包的根目录开始找相应的文件的。 一、packages、crates、modules packages: 通过cargo new 创建; crates: 通过cargo new --lib 创建。有根包和子包。即一个根包下可以包含多个子包。 modules: 通过关键字mod加模块定义 二、各种用法 src下有同个级:兄弟、父、子三个层级。 1、mod 往往是引入与当前文件同级的文件夹下(兄弟模块下)的文件。 2、crate 代表引用当前文件同级的文件。为同级文件时,意义和self相同。但如果是同级文件夹,不能混用。 3、super super:代表当前文件的上一级目录(父模块) 。super后面可以直接接函数。也可以接“*”,表示所有函数。 4、self 见crate 5、pub use 三、桥 在src下,往往有一个子目录,比如名字叫core. 里面还有两个文件,read.rs,write.rs.此时,需要有一个文件把这两个文件串起来。 此时,可以在core目录同级,建一个core.rs文件,把core目录下的两个文件串起来,对外可见。 我称这种与目录相同的rs文件为桥(个人定义,不规范)文件。 比如: pub mod a; pub mod c; pub use a::*; //不能省