2020年12月25日

摘要: 在学习rust的过程中,了解了高阶函数的知识,说白了就是函数可以作为参数,也可以返回一个函数,正好最近看到了scip公开课里面讲高阶过程这一章,有个求平方根的过程,里面的lisp实现相当的简洁优美,基本是对数学公式的形式化书写。这里用rust实现一下,看看区别有多大。 主要实现了传入函数作为参数,并 阅读全文
posted @ 2020-12-25 20:38 tycoon3 阅读(512) 评论(0) 推荐(0)
摘要: Rust点滴: 闭包那点事儿 概述 我们常常需要回调函数的功能, 需要函数并不是在创建时执行, 而是以回调的方式, 在需要的时候延迟执行. 并且, 常常需要在函数中获取环境中的一些信息, 又不需要将其作为函数参数传入. 这种应用场景就需要闭包这一工具了. 闭包是持有外部环境变量的函数. 所谓外部环境 阅读全文
posted @ 2020-12-25 20:37 tycoon3 阅读(486) 评论(0) 推荐(0)
摘要: 迭代器与闭包 fn main() { let vec_1 = vec![1, 2, 3,4,5]; let vec_2 = vec!["a","b","c","d","e"]; //对vec的`iter()`举出`i32`,(通过用`x`匹配)把它解构成`i32`。 //对vec的`into_ite 阅读全文
posted @ 2020-12-25 20:31 tycoon3 阅读(223) 评论(0) 推荐(0)
摘要: 返回闭包错误例子: fn returns_closure() -> Fn(i32) -> i32 { |x| x + 1 }正确例子: fn returns_closure() -> Box<dyn Fn(i32) -> i32> { Box::new(|x| x + 1)} fn main() { 阅读全文
posted @ 2020-12-25 20:23 tycoon3 阅读(108) 评论(0) 推荐(0)
摘要: 函数指针 我们讨论过了如何向函数传递闭包;也可以向函数传递常规函数!这在我们希望传递已经定义的函数而不是重新定义闭包作为参数时很有用。通过函数指针允许我们使用函数作为另一个函数的参数。函数的类型是 fn (使用小写的 “f” )以免与 Fn 闭包 trait 相混淆。fn 被称为 函数指针(func 阅读全文
posted @ 2020-12-25 20:22 tycoon3 阅读(134) 评论(0) 推荐(0)
摘要: 闭包会捕获其环境 闭包中可以使用x变量。 fn main() { let x = 4; let equal_to_x = |z| z == x; println!("{:?}", x); let y = 4; assert!(equal_to_x(y)); } 而在函数中,则无法使用x变量。 fn 阅读全文
posted @ 2020-12-25 19:55 tycoon3 阅读(217) 评论(0) 推荐(0)
摘要: https://zhuanlan.zhihu.com/p/184907190 https://colobu.com/2020/03/05/A-half-hour-to-learn-Rust/ Introduction Moves and copies are fundamental concepts 阅读全文
posted @ 2020-12-25 19:41 tycoon3 阅读(191) 评论(0) 推荐(0)
摘要: 闭包是什么? 先来看看维基百科上的描述: 在计算机科学中,闭包(英语:Closure),又称词法闭包(Lexical Closure)或函数闭包(function closures),是引用了自由变量的函数。这个被引用的自由变量将和这个函数一同存在,即使已经离开了创造它的环境也不例外。所以,有另一种 阅读全文
posted @ 2020-12-25 17:57 tycoon3 阅读(7127) 评论(0) 推荐(3)
摘要: struct Morpheus { blue_pill: f32, red_pill: i64, } fn main() { let f = Morpheus { blue_pill: 0.0, red_pill: 0 }; let copy = f.clone(); // and now we c 阅读全文
posted @ 2020-12-25 17:41 tycoon3 阅读(207) 评论(1) 推荐(0)
摘要: https://docs.rs/socket-io/0.1.1/src/socket_io/.cargo/registry/src/github.com-1ecc6299db9ec823/socket-io-0.1.1/src/socket.rs.html 阅读全文
posted @ 2020-12-25 17:38 tycoon3 阅读(448) 评论(0) 推荐(0)
摘要: I decided that I wanted to learn a new programming language in 2019. After a bit of research, I settled upon Rust due to its speed, novel ideas about 阅读全文
posted @ 2020-12-25 17:25 tycoon3 阅读(411) 评论(0) 推荐(1)
摘要: 吴斌的博客 » 【firecracker】系统启动与epoll事件循环 在分析完firecracker虚拟机中各个子系统的运行时原理和初始化流程后,最后我们整体分析一下firecracker的系统启动过程,并重点分析IO线程(fc_vmm)所采用的epoll事件循环框架。 回顾首文中介绍的firec 阅读全文
posted @ 2020-12-25 17:11 tycoon3 阅读(132) 评论(0) 推荐(0)
摘要: Vec 定义了一个动态增长的数组,与java ArrayList类似。基本也定义了增删改查操作: pub fn push(&mut self, value: T) pub fn remove(&mut self, index: usize) pub fn get<I>(&self, index: I 阅读全文
posted @ 2020-12-25 16:46 tycoon3 阅读(528) 评论(0) 推荐(0)
摘要: https://kaisery.github.io/trpl-zh-cn/ch16-01-threads.html use std::thread; use std::time::Duration; fn main() { thread::spawn(|| { for i in 1..10 { pr 阅读全文
posted @ 2020-12-25 16:28 tycoon3 阅读(197) 评论(0) 推荐(0)
摘要: https://wiki.jikexueyuan.com/project/rust-primer/rcarc/rcarc.html Rc 和 Arc Rust 建立在所有权之上的这一套机制,它要求一个资源同一时刻有且只能有一个拥有所有权的绑定或 &mut 引用,这在大部分的情况下保证了内存的安全。但 阅读全文
posted @ 2020-12-25 16:17 tycoon3 阅读(1744) 评论(0) 推荐(0)
摘要: https://zhuanlan.zhihu.com/p/109242831 fn main() { let path = "/tmp/dat"; println!("{}", read_file(path)); } fn read_file(path: &str) -> String { std: 阅读全文
posted @ 2020-12-25 16:04 tycoon3 阅读(1059) 评论(0) 推荐(0)
摘要: [root@bogon option]# rm -rf target/ [root@bogon option]# cargo build Compiling own v0.1.0 (/data2/rust/option) Finished dev [unoptimized + debuginfo] 阅读全文
posted @ 2020-12-25 15:47 tycoon3 阅读(306) 评论(0) 推荐(0)
摘要: Rust 中的属性,可以分为以下四大类。 Macro attributes - 宏属性 Derive macro helper attributes - 派生宏辅助属性 Tool attributes - 工具属性 Built-in attributes - 内建属性 Macro Attribute 阅读全文
posted @ 2020-12-25 15:32 tycoon3 阅读(922) 评论(0) 推荐(0)
摘要: [root@bogon rust]# mkdir learn_marco2 [root@bogon rust]# cd learn_marco2/ [root@bogon learn_marco2]# cargo new hello_macro --lib Created library `hell 阅读全文
posted @ 2020-12-25 14:45 tycoon3 阅读(199) 评论(0) 推荐(0)
摘要: 1、Trait是什么? 一个Trait描述了一种抽象接口(找不到很合适的词),这个抽象接口可以被类型继承。Trait只能由三部分组成(可能只包含部分): functions(方法) types(类型) constants(常量) 所有的Trait都定义了一个隐含类型Self,其指向实现该Trait的 阅读全文
posted @ 2020-12-25 14:13 tycoon3 阅读(652) 评论(0) 推荐(0)
摘要: 应用:简单HTTP服务器 https://learnku.com/docs/async-book/2018/http_server_example/4789 //例子二 use futures::{ self, executor}; async fn learn_song() { println!( 阅读全文
posted @ 2020-12-25 12:02 tycoon3 阅读(1498) 评论(0) 推荐(0)
摘要: cargo check [root@bogon async]# cargo check Checking own v0.1.0 (/data2/rust/async) error[E0670]: `async fn` is not permitted in the 2015 edition --> 阅读全文
posted @ 2020-12-25 11:53 tycoon3 阅读(936) 评论(0) 推荐(0)
摘要: src/main.rs #[derive(Debug)] struct MyType { name: String } impl MyType { fn do_something(self, age: u32) { //等价于 fn do_something(self: Self, age: u32 阅读全文
posted @ 2020-12-25 11:21 tycoon3 阅读(248) 评论(0) 推荐(0)
摘要: Firecracker Firecracker is a new light KVM-based hypervisor written in Rust and announced during last AWS re:Invent in 2018. But unlike QEMU, Firecrac 阅读全文
posted @ 2020-12-25 10:14 tycoon3 阅读(340) 评论(0) 推荐(0)
摘要: root@ubuntu:~# gdb firecracker /data1/core/core.53227 GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git Copyright (C) 2018 Free Software Foundation, 阅读全文
posted @ 2020-12-25 10:12 tycoon3 阅读(141) 评论(0) 推荐(0)
摘要: $ gdb --configuration 这个GDB配置如下:配置--host = x86_64-apple-darwin13.1.0 --target = x86_64-apple-darwin13.1.0 --with-auto-load-dir =:$ {prefix} / share / 阅读全文
posted @ 2020-12-25 10:10 tycoon3 阅读(362) 评论(0) 推荐(0)
摘要: git clone https://github.com/firecracker-microvm/firecracker git checkout tags/v0.10.1 [root@bogon firecracker]# ls api_server CHANGELOG.md devices du 阅读全文
posted @ 2020-12-25 09:16 tycoon3 阅读(316) 评论(0) 推荐(0)

导航