Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/ZhangHanDong/tao-of-rust-codes
/ functions
Functions
413 in github.com/ZhangHanDong/tao-of-rust-codes
⨍
Functions
413
◇
Types & classes
88
↓ 1 callers
Function
sum_of_even
(n: *const c_uint, len: c_uint)
src/ch13/callrust/src/lib.rs:8
↓ 1 callers
Method
swim
(&self)
src/ch03/trait_limit.rs:157
↓ 1 callers
Function
test_copy
(i: T)
src/ch03/tag_trait.rs:53
↓ 1 callers
Function
test_load_csv
()
src/ch10/csv_challenge/benches/file_op_bench.rs:17
↓ 1 callers
Function
test_load_csv
()
src/ch10/csv_challenge/tests/integration_test.rs:16
↓ 1 callers
Function
test_read_write_csv
()
src/ch10/csv_challenge/benches/file_op_bench.rs:29
↓ 1 callers
Function
test_replace_column
()
src/ch10/csv_challenge/tests/integration_test.rs:21
↓ 1 callers
Function
test_write_csv
()
src/ch10/csv_challenge/tests/integration_test.rs:28
↓ 1 callers
Function
verify
(number: usize)
src/ch11/pow/src/main.rs:17
↓ 1 callers
Function
worker
()
src/ch11/simd-demo/src/main.rs:56
↓ 1 callers
Function
write
(data: &str, filename: &str)
src/ch10/csv_challenge/src/core/read.rs:41
Function
Database
()
src/ch13/callrust/Node.js/database.js:10
Method
__enter__
(self)
src/ch13/callrust/Python/database.py:24
Method
__exit__
(self, exc_type, exc_value, traceback)
src/ch13/callrust/Python/database.py:26
Method
__init__
(self)
src/ch13/callrust/Python/database.py:22
Function
add
fn add(i: i32, j: i32) -> i32 { i + j + out}
src/ch02/function.rs:149
Method
add
(self, other: u64)
src/ch03/traits.rs:206
Method
add
(self, other: i32)
src/ch03/trait_limit.rs:41
Function
add_one
(x: i32)
src/ch13/hello_wasm/src/lib.rs:7
Function
almost_ready
(value: i32)
src/ch11/futures-demo/src/main.rs:22
Function
annotation
# 注释 Basic usage: ``` /// # 文档注释: Sum函数 /// 该函数为求和函数 /// # usage: /// assert_eq!(3, sum(1, 2)); fn sum(a: i32, b: i32) -> i32 { a + b } pub fn an
src/ch02/annotation.rs:28
Function
answer
# answer Basic usage: ``` // extern crate std; // 声明语句 // use std::prelude::v1::*; // 声明语句 pub fn answer() -> (){ let a = 40; // 声明语句 let b
src/ch02/mod.rs:39
Function
any_function
# 使用Any进行反射 Basic usage: 使用is函数进行类型判断 ``` use std::any::{Any, TypeId}; enum E { H, He, Li} struct S { x: u8, y: u8, z: u16 } fn main() { let v1 =
src/ch12/reflect.rs:110
Function
array_type
# 基本数据类型:array类型 Basic usage: ``` fn array_type() { let arr: [i32; 3] = [1, 2, 3]; // 定义一个[i32; 3]类型的数组,默认不可变 let mut mut_arr = [1, 2, 3];
src/ch02/primitives.rs:127
Function
associated_type
# trait: 关联类型 Base usage: ``` pub fn associated_type(){ #[derive(Debug, PartialEq)] struct Foo(i32); #[derive(Debug, PartialEq)] struct Bar(i32, i32
src/ch03/traits.rs:35
Function
atomic_demo
# 原子类型 Basic usage: 使用原子类型实现自旋锁 ```rust use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; use std::thread; fn main() { let spinloc
src/ch11/atomics.rs:21
Function
attr_with_args
(args: TokenStream, input: TokenStream)
src/ch12/simple_proc_macro/src/lib.rs:23
Function
auto_deref
# 类型转换:自动解引用(For SmartPointer) Base usage: `Vec<T>`实现了`Deref<Target=[T]>` ``` fn foo(s: &[i32]){ println!("{:?}", s[0]); } let v = vec![1,2,3]; foo
src/ch03/type_cast.rs:30
Method
backtrace
(&self)
src/ch09/failures_crate/src/lib.rs:30
Function
bases
# 字符串编码 Base usage: 从Unicode到UTF-8编码过程 ```rust use std::str; fn main() { let tao = str::from_utf8(&[0xE9u8, 0x81u8, 0x93u8]).unwrap(); // 将UTF-8序列转为
src/ch08/bases.rs:94
Function
bases
()
src/ch08/vectors.rs:188
Function
bench_read_100times
(b: &mut Bencher)
src/ch10/csv_challenge/benches/file_op_bench.rs:11
Function
bench_rw_100times
(b: &mut Bencher)
src/ch10/csv_challenge/benches/file_op_bench.rs:22
Function
binary_heap
# 优先队列:BinaryHeap Basic usage: ``` use std::collections::BinaryHeap; fn binary_heap() { let mut heap = BinaryHeap::new(); assert_eq!(heap.peek(), No
src/ch02/collections.rs:265
Function
binding_and_func
# 资源管理: Base usage: 变量与函数 变量默认存储在栈中 ``` fn main() { let x: i32; // Rust会检查未初始化的变量,并报错 println!("{}", x); } ``` Base usage: if 分支检查 ``` fn main() {
src/ch04/resource_management.rs:58
Function
bool_type
# 基本数据类型:布尔值 Basic usage: ``` fn bool_type() { let x = true; // bool类型可以自动推断 let y: bool = false; // bool值分为true和false let x = 5; if x > 1 { print
src/ch02/primitives.rs:16
Function
borrow
# 借用与引用 Base usage: 为函数传递数组,使用可变绑定作为参数 因为传入的是不可变,而经过函数参数的模式匹配,成为了可变参数 ```rust fn foo(mut v: [i32; 3]) -> [i32; 3] { v[0] = 3; assert_eq!([3,2,3], v);
src/ch05/borrow.rs:30
Function
borrow_check
# 借用检查 Base usage: 借用检查保证了内存安全 试想,input 和 output 如果将同一个变量的 不可变和可变引用同时传入会发生什么? ```rust fn compute(input: &u32, output: &mut u32) { if *input > 10 { o
src/ch05/borrow.rs:138
Function
borrow_ck_problem
# NLL: 非词法作用域生命周期 以下代码目前在 Rust 2015版本中 会出错,但是选择Rust 2018 edition将正常编译 可以去play.rust-lang.org选择2018 edtion版本尝试 Base usage: 案例1 ```rust struct Foo; im
src/ch05/nll.rs:116
Function
bottom_type
# 底类型:应用 Base usage ``` #![feature(never_type)] fn foo() -> ! { // do something loop { println!("jh"); } } let i = if false { foo(); } else { 100 };
src/ch03/bottom_type.rs:18
Function
box_demo
# 智能指针:Box<T> Basic usage: ``` fn box_demo(){ #[derive(PartialEq, Debug)] struct Point { x: f64, y: f64, } // 将Point实例装箱(放到堆内存) let box_point = Box:
src/ch02/smart_pointer.rs:19
Function
box_demo
# 智能指针和所有权: Box<T> Base usage: Box<T>独占所有权 ```rust fn main(){ let x = Box::new("hello"); let y = x; // error[E0382]: use of moved value: `x` // prin
src/ch05/smart_pointer.rs:43
Function
bubble_sort_demo
# 借用与引用 Base usage: 冒泡排序 ```rust fn bubble_sort(a: &mut Vec<i32>) { let mut n = a.len(); // 获取数组长度 while n > 0 { // 初始化遍历游标,max_ptr始终指向最大值 let (mut
src/ch05/borrow.rs:72
Function
call_it
(f: &F)
src/ch06/closures.rs:147
Function
call_it_mut
(f: &mut F)
src/ch06/closures.rs:150
Function
call_it_once
(f: F)
src/ch06/closures.rs:153
Method
cause
(&self)
src/ch09/examples/io_origin_refactor4.rs:35
Method
cause
(&self)
src/ch09/examples/io_origin_refactor.rs:32
Method
cause
(&self)
src/ch09/examples/io_origin_refactor3.rs:33
Method
cause
(&self)
src/ch09/failures_crate/src/lib.rs:27
Function
channel_demo
# CSP并发模型 查看随书源码中的pow库,可以查看channel实现工作量证明的示例 Basic usage: 流通道channel示例 异步channel ```rust use std::thread; use std::sync::mpsc::channel; fn main()
src/ch11/channels.rs:101
Function
char_type
# 基本数据类型:char类型 Basic usage: ``` fn char_type(){ let x = 'r'; let x = 'Ú'; println!("{}", '\''); println!("{}", '\\'); println!("{}", '\n'); println
src/ch02/primitives.rs:93
Function
closure
# 闭包 Basic usage: ``` pub fn closure(){ let out = 42; // 普通函数 // fn add(i: i32, j: i32) -> i32 { i + j + out} fn add(i: i32, j: i32) -> i32 { i +
src/ch02/function.rs:146
Function
closure_gen_type
# 闭包生成类型 Base usage: Copy语义自动实现Fn ```rust fn main() { let s = "hello"; let c = ||{ println!("{:?}", s) }; c(); c(); println!("{:?}", s); } ``` Bas
src/ch06/closures.rs:351
Function
closure_math
# 闭包: 作为参数 Basic usage: ``` pub fn closure_math<F: Fn() -> i32>(op: F) -> i32 { op() } let a = 2; let b = 3; assert_eq!(closure_math(|| a + b), 5);
src/ch02/function.rs:172
Function
closures
# 闭包 Base usage: 将计数函数改为闭包形式(Rust 2015) ```rust fn counter(i: i32) -> Box<Fn(i32) -> i32> { Box::new(move |n: i32| n + i ) } fn main() { let f = cou
src/ch06/closures.rs:47
Function
color_terminal
# 结构体: 面向对象示例 Base usage: 让终端的输出带上颜色 color.rs ```rust use std::fmt; struct ColoredString { input: String, fgcolor: String, bgcolor: String, } impl
src/ch07/structs.rs:336
Function
compare_size
# 动态大小类型:比较`&[u32; 5]`和`&mut [u32]`的空间占用 Base usage: ``` fn compare_size(){ assert_eq!(std::mem::size_of::<&[u32; 5]>(), 8); assert_eq!(std::mem::si
src/ch03/type_size.rs:100
Function
contract
# 使用Unsafe进行安全抽象 安全抽象的时候需要注意什么? --- Basic usage: Vec<T>的insert方法源码示意 正因为存在下面那两个判断条件,才保证了该方法的安全性 ```rust pub fn insert(&mut self, index: usize, e
src/ch13/security_abstract.rs:30
Function
cow
# 智能指针和所有权: Cow写时复制 是一个枚举类型的智能指针,包括两个可选值:Borrowed,用于包裹引用,以及Owned,用于包裹所有者 一般用于读多写少的场景 Base usage: Cow ```rust use std::borrow::Cow; fn abs_all(input:
src/ch05/smart_pointer.rs:232
Function
crossbeam_demo
# Crossbeam使用 Basic usage: 使用标准库,出错 ```rust let array = [1, 2, 3]; let mut guards = vec![]; // 这样也可以 for &i in &array { for i in &array { let guard
src/ch11/crossbeam.rs:200
Function
custom_closures
# 自定义闭包实现 Base usage: ```rust #![feature(unboxed_closures, fn_traits)] struct Closure { env_var: u32, } impl FnOnce<()> for Closure { type Output =
src/ch06/closures.rs:123
Function
declarative_macros
# 宏系统: 声明宏 Basic usage: ```rust macro_rules! unless { ($arg:expr, $branch:expr) => ( if !$arg { $branch };); } fn cmp(a: i32, b: i32) { unless!( a >
src/ch12/macros.rs:222
Function
deref_move_type
# 解引用操作将获得所有权 Base usage: 解引用移动语义类型需要注意 ```rust fn join(s: &String) -> String { let append = *s; "Hello".to_string() + &append } fn main(){ let x =
src/ch05/borrow.rs:169
Function
derive
(input: TokenStream)
src/ch12/derive-new/src/lib.rs:10
Function
derive
(input: TokenStream)
src/ch12/simple_proc_macro/src/lib.rs:9
Method
description
(&self)
src/ch09/examples/io_origin_refactor4.rs:28
Method
description
(&self)
src/ch09/examples/io_origin_refactor.rs:25
Method
description
(&self)
src/ch09/examples/io_origin_refactor3.rs:26
Function
design_patterns
# 设计模式 Base usage: 建造者模式 Rust常用设计模式之一,标准库中std::process::Command就是典型 ```rust struct Circle { x: f64, y: f64, radius: f64, } struct CircleBuilder { x
src/ch07/design_pattern.rs:271
Method
drop
(&mut self)
src/ch04/memory_leak.rs:42
Method
drop
(&mut self)
src/ch04/raii.rs:96
Method
drop
(&mut self)
src/ch11/thread_pool/src/main.rs:170
Function
drop_ck_test
# Drop检查 使用不当的话,Drop检查会引起UB Basic usage: 声明元组变量测试dropck 在Safe Rust中由dropck引起的问题,借用检查会安全识别,从而引起错误阻止程序编译 ```rust use std::fmt; #[derive(Copy, Clone
src/ch13/security_abstract.rs:674
Function
drop_demo
# RAII: 确定性析构 Base usage: 实现Drop ``` use std::ops::Drop; #[derive(Debug)] struct S(i32); impl Drop for S { fn drop(&mut self) { println!("drop {}", s
src/ch04/raii.rs:91
Function
drop_order
# 结构体: 析构顺序 Base usage: 本地变量 ```rust struct PrintDrop(&'static str); impl Drop for PrintDrop { fn drop(&mut self) { println!("Dropping {}", self.0)
src/ch07/structs.rs:480
Function
eliminate_failure
# 消除失败 1. 利用类型系统 2. 利用断言 Base usage: 利用类型系统消除程序中的失败 ```rust fn sum(a: i32, b: i32) -> i32 { a + b } fn main() { sum(1u32, 2u32); // 违反契约,报错 } ```
src/ch09/failures.rs:29
Function
error_handle
# 分层错误处理 1. Option 2. Error 3. Panic 4. Abort Base usage: 使用Option<T> ```rust fn get_shortest(names: Vec<&str>) -> Option<&str> { if names.len() >
src/ch09/errors.rs:479
Function
expand_roman
计算罗马数字,转换为阿拉伯数字
src/ch12/plugin_demo/src/lib.rs:22
Function
fizz_buzz
# 函数定义 Basic usage: ``` pub fn fizz_buzz(num: i32) -> String { if num % 15 == 0 { return "fizzbuzz".to_string(); } else if num % 3 == 0 { return "fi
src/ch02/function.rs:22
Function
fly_dyn
# 零成本抽象 fly_dyn ``` struct Duck; struct Pig; trait Fly { fn fly(&self) -> bool; } impl Fly for Duck { fn fly(&self) -> bool { return true; } } impl
src/ch01/mod.rs:106
Function
fly_static
# 零成本抽象 fly_static ``` struct Duck; struct Pig; trait Fly { fn fly(&self) -> bool; } impl Fly for Duck { fn fly(&self) -> bool { return true; } } i
src/ch01/mod.rs:71
Function
fly_static
(s: impl Fly+Debug)
src/ch03/abstract_type.rs:139
Method
fmt
(&self, f: &mut fmt::Formatter)
src/ch09/examples/io_origin_refactor4.rs:19
Method
fmt
(&self, f: &mut fmt::Formatter)
src/ch09/examples/io_origin_refactor.rs:16
Method
fmt
(&self, f: &mut fmt::Formatter)
src/ch09/examples/io_origin_refactor3.rs:17
Method
fmt
(&self, f: &mut std::fmt::Formatter)
src/ch09/failures_crate/src/lib.rs:36
Method
fmt
(&self, f: &mut Formatter)
src/ch02/generics_trait.rs:92
Method
fmt
(&self, f: &mut fmt::Formatter)
src/appendix/lldb.rs:43
Function
foo
# 泛型 Base usage: 自定义泛型函数 ``` fn foo<T>(x: T) -> T { return x; } assert_eq!(foo(1), 1); assert_eq!(foo("hello"), "hello"); ``` Base usage: 自定义泛型结构体
src/ch03/generics.rs:32
Function
foo
()
src/ch02/primitives.rs:349
Function
for_fizzbuzz
# for表达式 Basic usage: ``` fn for_fizzbuzz() { for n in 1..101 { if n % 15 == 0 { println!("fizzbuzz"); } else if n % 3 == 0 { println!("fizz"); } el
src/ch02/control_flow.rs:124
Function
forget_drop
# 使用`std::mem::forget`跳过Drop Basic usage: 转移结构体中字段所有权 - V1 ```rust struct A; struct B; struct Foo { a: A, b: B } impl Foo { fn take(self) -> (A, B
src/ch13/security_abstract.rs:744
Function
fqsfd
# 类型转换:as 操作符 Base usage: 无歧义完全限定语法(Fully Qualified Syntax for Disambiguation) 曾用名: 通用函数调用语法(UFCS) ``` struct S(i32); trait A { fn test(&self, i: i32
src/ch03/type_cast.rs:111
Method
from
(tup: (u32, u32))
src/ch13/callrust/src/lib.rs:67
Method
from
(err: io::Error)
src/ch09/examples/io_origin_refactor4.rs:45
Method
from
(err: io::Error)
src/ch09/examples/io_origin_refactor.rs:40
Method
from
(err: io::Error)
src/ch09/examples/io_origin_refactor3.rs:41
Method
from
(err: std::io::Error)
src/ch09/failures_crate/src/lib.rs:42
Method
from
(e: io::Error)
src/ch10/csv_challenge/src/err.rs:8
← previous
next →
101–200 of 413, ranked by callers