随笔分类 -  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 阅读全文
posted @ 2025-01-01 14:47 念秋 阅读(17) 评论(0) 推荐(0) 编辑
摘要:一.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 阅读全文
posted @ 2024-12-28 17:25 念秋 阅读(418) 评论(0) 推荐(0) 编辑
摘要:前提知识: rust里面有move,copy,clone。 所有对象都有一个类型,具体所有权。 比如 #[derive(Debug)] struct Complex { real: f64, imag: f64, } fn main() { let a = Complex{real:1.,imag: 阅读全文
posted @ 2024-12-27 15:17 念秋 阅读(12) 评论(0) 推荐(0) 编辑
摘要:1.HahsMap https://rustwiki.org/zh-CN/std/collections/struct.HashMap.html 跟着文档,查看一下hashmap的方法,调试,输出一下,就能学会使用了。 use std::collections::HashMap; use std:: 阅读全文
posted @ 2024-10-30 21:07 念秋 阅读(51) 评论(0) 推荐(0) 编辑
摘要:1.trait的基本使用 最基本的trait struct Person { name:String, id:i32, } struct Teacher { name:String, id:i32, } trait sayHello { fn say_hello(&self) { println!( 阅读全文
posted @ 2024-10-29 15:05 念秋 阅读(36) 评论(0) 推荐(0) 编辑
摘要:由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 阅读全文
posted @ 2024-10-28 23:48 念秋 阅读(43) 评论(0) 推荐(0) 编辑
摘要: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' 阅读全文
posted @ 2024-10-22 14:24 念秋 阅读(110) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示