随笔分类 - rust
记录一些rust语言的代码
摘要:1.Cell use std::cell::Cell; #[derive(Debug)] struct SomeStruct { regular_field: u8, special_field: Cell<u8>, } fn main() { let my_struct = SomeStruct
阅读全文
摘要:一.Windows下Rust与C/C++互相调用 1.C/C++调用rust 1.1动态库调用 1.1.1以LoadLibrary方式显示调用 add.rs #[no_mangle] // 防止 Rust 修改函数名 pub extern "C" fn hello_world() { println
阅读全文
摘要:前提知识: rust里面有move,copy,clone。 所有对象都有一个类型,具体所有权。 比如 #[derive(Debug)] struct Complex { real: f64, imag: f64, } fn main() { let a = Complex{real:1.,imag:
阅读全文
摘要:1.HahsMap https://rustwiki.org/zh-CN/std/collections/struct.HashMap.html 跟着文档,查看一下hashmap的方法,调试,输出一下,就能学会使用了。 use std::collections::HashMap; use std::
阅读全文
摘要:1.trait的基本使用 最基本的trait struct Person { name:String, id:i32, } struct Teacher { name:String, id:i32, } trait sayHello { fn say_hello(&self) { println!(
阅读全文
摘要:由C++指针和引用引发的思考 #include<iostream> using namespace std; void c1(int a) { a = 6; } void c2(int* a) { *a = 7; } void c3(int& a) { a = 8; } int main() { i
阅读全文
摘要:use std::collections::HashMap; use std::sync::OnceLock; const B64: [char; 65] = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'
阅读全文