rust

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

拜拜、爱过 提交于 2020-12-29 05:53:47
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

帅比萌擦擦* 提交于 2020-12-29 05:53:28
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Are nested matches a bad practice in idiomatic Rust?

筅森魡賤 提交于 2020-12-29 03:02:16
问题 I have a get_url_content function and don't care about errors (it's just a test). It returns an Option<String> . extern crate hyper; use std::io::Read; use hyper::client::Client; fn get_url_content(url: &str) -> Option<String> { let client = Client::new(); let mut s = String::new(); match client.get(url).send() { Ok(mut res) => { match res.read_to_string(&mut s) { Ok(_) => { Some(s) }, Err(_) => { None } } }, Err(_) => { None } } } This function works fine but I find it's not easy to read. I

Are nested matches a bad practice in idiomatic Rust?

别等时光非礼了梦想. 提交于 2020-12-29 02:59:27
问题 I have a get_url_content function and don't care about errors (it's just a test). It returns an Option<String> . extern crate hyper; use std::io::Read; use hyper::client::Client; fn get_url_content(url: &str) -> Option<String> { let client = Client::new(); let mut s = String::new(); match client.get(url).send() { Ok(mut res) => { match res.read_to_string(&mut s) { Ok(_) => { Some(s) }, Err(_) => { None } } }, Err(_) => { None } } } This function works fine but I find it's not easy to read. I

服务器端编程语言对比:C/C++, C#.NET, Java, Go, Rust

若如初见. 提交于 2020-12-28 01:23:30
对比指标 C/C++ C#.NET Java Go Rust 计算斐波那契数列第60个数字(循环实现) 计算斐波那契数列第10个数字(递归实现) uint16比特位的设置 uint16比特位的查找 自定义快速排序 自定义stack的pop/push 自定义链表的构建 自定义链表的查找 Protobuf消息编码 Protobuf消息解码 AES加密 AES解密 并发读写数据 格式化日志 申请48byte内存 自定义类型初始化 责任链方法调用 JSON编解码 内存直接拷贝 对象复制 字符串匹配 hashmap性能 自定义html解析 自定义html解析 获取当前时间戳 打印64k行日志 斐波那契数列三层调用处理(GRPC框架) 斐波那契数列三层调用处理(自定义框架) 来源: oschina 链接: https://my.oschina.net/u/4271269/blog/4845045

Rust编程进阶:002、在函数和结构体里面使用泛型

醉酒当歌 提交于 2020-12-28 01:01:04
1、泛型是具体类型或者其它属性的抽象替代,用于减少代码重复。 2、在函数定义中使用泛型。 创建一个项目learn_T: cargo new learn_T 修改src/main.rs文件: // 没有泛型 // for i32 fn largest_i32(list: &[i32]) -> i32 { let mut largest = list[0]; for &item in list.iter() { if item > largest { largest = item; } } largest } // for char fn largest_char(list: &[char]) -> char { let mut largest = list[0]; for &item in list.iter() { if item > largest { largest = item; } } largest } fn main() { let number_list = vec![1, 2, 23, 34, 8, 100]; let max_number = largest_i32(&number_list); println!("max_number = {}", max_number); let char_list = vec!['a', 'y', 'b']; let max

开源开发者为任天堂 N64 主机带来了新的 Linux 内核移植

拜拜、爱过 提交于 2020-12-27 10:06:13
开源开发者为任天堂 N64 主机带来了新的 Linux 内核移植 据 cnbeta 报道,最近主机游戏领域开源有一些新成就,索尼为 PS5 标配的 DualSense 手柄提供了官方 Linux 驱动程序。而任天堂 N64 主机亦迎来了 Linux 内核的新移植。作为一款距今已有 20 个年头的主机,该项目着实让粉丝们感到有些意外。曾为 Mesa 和 Linux 图形驱动作出过贡献的开源开发者于今年圣诞节期间正式宣布了这一喜讯。 拍一拍:总是有些极客愿意挑战一些有趣的事情。 Linux 5.10 的 Btrfs 性能严重衰退 据 cnbeta 报道,在紧急发布的维护版本更新中修复 RAID、AMDGPU 等问题之后,长期支持(LTS)的 Linux Kernel 5.10 内核再次爆出新问题:部分用户遭遇到了惊人的 Btrfs 性能倒退。例如解压一个大型 .tar.zst 文件,解压时间可能会从原本的 15 秒左右变成将近 5 分钟。不过,维护人员已经在圣诞节之前找到了问题根源,很快就能解决。 拍一拍:看来 Linus 对 5.10 要赶在圣诞节前推出有点乐观,所以才出现了这些问题。 Rust 编写的 Redox OS 0.6发布 据 slashdot 报道,基于微内核的 Rust 编写的操作系统 Redox OS 出了一个新的圣诞版本,有许多错误修复和新功能。完全重写了其 RMM

How does Rust's 128-bit integer `i128` work on a 64-bit system?

人盡茶涼 提交于 2020-12-27 07:54:05
问题 Rust has 128-bit integers, these are denoted with the data type i128 (and u128 for unsigned ints): let a: i128 = 170141183460469231731687303715884105727; How does Rust make these i128 values work on a 64-bit system; e.g. how does it do arithmetic on these? Since, as far as I know, the value cannot fit in one register of a x86-64 CPU, does the compiler somehow use 2 registers for one i128 value? Or are they instead using some kind of big integer struct to represent them? 回答1: All Rust's

Why can't I call gen_range with two i32 arguments?

▼魔方 西西 提交于 2020-12-27 07:14:51
问题 I have this code but it doesn't compile: use rand::Rng; use std::io; fn main() { println!("Guess the number!"); let secret_number = rand::thread_rng().gen_range(0, 101); println!("The secret number is: {}", secret_number); println!("Please input your guess."); let mut guess = String::new(); io::stdin() .read_line(&mut guess) .expect("Failed to read line"); println!("You guessed: {}", guess); } Compile error: error[E0061]: this function takes 1 argument but 2 arguments were supplied --> src