Rust
介绍Rust
编号94530
新时代 积极 向上 奋斗 好 青年
展开
-
Rust特征与泛型区别点
1. Rust的特征与泛型1.1 先上特征代码:use std::boxed::Box;// 定义一个特征pub trait Animal{ fn bark(&self);}pub struct Dog{ pub name: String,}pub struct Chicken{ pub name: String,}// 实现一个特征impl Animal for Dog{ fn bark(&self){ printl原创 2020-08-16 14:10:25 · 354 阅读 · 0 评论 -
Rust多线程数据共享
1. 怎么创建线程我们都知道Java中通过实现Runnable接口或继承Thread类,来完成一个线程的创建,那么在Rust中是如何实现一个线程的呢?代码如下。fn how_to_create_a_thread(){ // 创建一个线程 let thread_handle = thread::spawn(|| { println!("Thread inner"); }); // 阻塞线程,并等待其自己执行完毕 thread_handle.join().u原创 2020-07-17 21:32:38 · 1341 阅读 · 0 评论