随笔分类 -  Rust

学习笔记
摘要:// 这是第一种注释方式 /* 这是第二种注释方式 */ /* * 多行注释 * 多行注释 * 多行注释 */文档注释 /// Adds one to the number given. /// /// # Examples /// /// ``` /// let x = add(1, 2); // 阅读全文
posted @ 2022-06-14 12:58 方诚 阅读(38) 评论(0) 推荐(0)
摘要:Rc<T>, the Reference Counted Smart Pointer Rc,多引用小指针,可以让一个地址被多个对象引用,每多一个对象,引用个数+1 In the majority of cases, ownership is clear: you know exactly which 阅读全文
posted @ 2022-01-16 13:09 方诚 阅读(67) 评论(0) 推荐(0)
摘要:Box Box是一个指针,具有固定长度, 指针在栈上,指针指向的数据在堆上, 这个复合类型是rust为用户提供的,可以实现递归调用的一个类型,它不会提升性能, 所以,除了递归,一般不用这个. The most straightforward smart pointer is a box, whose 阅读全文
posted @ 2021-12-28 12:26 方诚 阅读(389) 评论(0) 推荐(0)
摘要:fn add_one_v1 (x: u32) -> u32 { x + 1 } let add_one_v2 = |x: u32| -> u32 { x + 1 }; let add_one_v3 = |x| { x + 1 }; let add_one_v4 = |x| x + 1 ; pub f 阅读全文
posted @ 2021-11-03 13:31 方诚 阅读(80) 评论(0) 推荐(0)
摘要:自定义的命令行参数解析 这是本人自己写的一套方法,用着感觉比较舒服,官方的参数解析请跳过此部分看后面的部分 #![allow(unused)] use std::env; extern crate mij; use mij::base::arg; fn parse_args(mut num:&mut 阅读全文
posted @ 2021-09-28 14:48 方诚 阅读(848) 评论(0) 推荐(0)
摘要:概述 使用rust-cpython将rust程序做为python模块调用; 通常为了提高python的性能; 参考-github https://github.com/dgrunwald/rust-cpython 环境 系统:本次示例为ubantu20.04,等效于centos7 python: p 阅读全文
posted @ 2021-09-04 22:24 方诚 阅读(2571) 评论(0) 推荐(0)
摘要:Cargo.toml [dependencies] lazy_static = "1.4.0" main.rs #[macro_use] extern crate lazy_static; use std::collections::HashMap; lazy_static! { static re 阅读全文
posted @ 2021-03-05 09:49 方诚 阅读(334) 评论(0) 推荐(0)
摘要:允许未使用的方法,写在文件开头,可过滤过掉该项提示 #![allow(unused)] 阅读全文
posted @ 2020-12-28 12:36 方诚 阅读(346) 评论(0) 推荐(0)
摘要:The rust String is a growable, mutable, owned, UTF-8 encoded string type. &str ,切片,是按UTF-8编码对String中字符的一个引用,不具有owned。 不具有owner关系,是非常非常重要的一区别,看下面代码 pub 阅读全文
posted @ 2020-12-04 14:13 方诚 阅读(311) 评论(0) 推荐(0)
摘要:Every programming language has tools for effectively handling the duplication of concepts. In Rust, one such tool is generics. Generics are abstract s 阅读全文
posted @ 2020-11-16 13:02 方诚 阅读(180) 评论(0) 推荐(0)
摘要:1.1 Rust安装 3.5 Rust Generic Types, Traits, and Lifetimes 3.6 String 与 切片&str的区别 https://openslr.magicdatatech.com/resources/33/data_aishell.tgz 阅读全文
posted @ 2020-11-12 12:14 方诚 阅读(128) 评论(0) 推荐(0)
摘要:Unrecoverable Errors with panic! Sometimes, bad things happen in your code, and there’s nothing you can do about it. In these cases, Rust has the pani 阅读全文
posted @ 2020-10-16 10:35 方诚 阅读(1177) 评论(0) 推荐(0)
摘要:The type HashMap<K, V> stores a mapping of keys of type K to values of type V. It does this via a hashing function, which determines how it places the 阅读全文
posted @ 2020-09-09 12:51 方诚 阅读(351) 评论(0) 推荐(0)
摘要:What Is a String? The String type, which is provided by Rust’s standard library rather than coded into the core language, is a growable, mutable, owne 阅读全文
posted @ 2020-08-24 12:46 方诚
摘要:vec创建 use std::option::Option::*; fn main() { println!(" "); test_vec1(); test_vec2(); } fn test_vec1(){ //let v: Vec<i32> = Vec::new(); let mut v1 = 阅读全文
posted @ 2020-08-13 12:53 方诚
摘要:$ rustc --versionrustc 1.44.0 (49cae5576 2020-06-01) 将代码存在到不同的文件 main.rs mod aa; fn main() { println!(" "); aa::aa1(); } mod aa表示引入aa模块,在rust中一个文件名就代表 阅读全文
posted @ 2020-07-07 12:30 方诚 阅读(963) 评论(0) 推荐(0)
摘要:Enums and Pattern Matching 摘要 枚举定义 enum IpAddrKind { V4, V6, } 枚举方法 fn main() { enum Message { Quit, Move { x: i32, y: i32 }, Write(String), ChangeCol 阅读全文
posted @ 2020-06-09 12:50 方诚 阅读(659) 评论(0) 推荐(0)
摘要:随机数、数字对比、控制台输入 use std::io; use std::cmp::Ordering; use rand::Rng; fn main() { println!("please input a number(1-10):"); let mut ss = String::new(); i 阅读全文
posted @ 2020-03-16 13:00 方诚 阅读(255) 评论(0) 推荐(0)
摘要:A struct, or structure, is a custom data type that lets you name and package together multiple related values that make up a meaningful group. Definin 阅读全文
posted @ 2019-05-13 13:03 方诚 阅读(227) 评论(0) 推荐(0)
摘要:字符串操作 fn first_word(s: &String) -> usize { let bytes = s.as_bytes(); for (i, &item) in bytes.iter().enumerate() { if item == b' ' { return i; } } s.le 阅读全文
posted @ 2019-04-12 13:03 方诚 阅读(396) 评论(0) 推荐(0)