Rust  (github)

1. install (https://rustup.rs/)

2. play on line

curl https://sh.rustup.rs -sSf | sh
echo 'PATH="$PATH:$HOME/.cargo/bin"' >> ~/.bashrc
rustup doc

  https://www.jdoodle.com/execute-rust-online

https://www.tutorialspoint.com/compile_rust_online.php

Tutorial org learn (entry)

1. org examaple (CN)

github

# install book local
git clone https://github.com/rust-lang-cn/rust-by-example-cn
cd rust-by-example-cn
cargo install mdbook
mdbook build
mdbook serve

grammar

formatting-traits  

2. book (Translations/CN)   (Chinese)

github(CN)

github(EN)

rustup docs --book

3. rustlings course

4. Rust 基础笔记

5. view a project

cargo doc --open 

6. Rust 语言中文版  

7. Rust教程   

8. Rust 编程语言入门

Grow with Rust

THE STANDARD LIBRARY

Comprehensive guide to the Rust standard library APIs.

EDITION GUIDE

Guide to the Rust editions.

CARGO BOOK

A book on Rust’s package manager and build system.

RUSTDOC BOOK

Learn how to make awesome documentation for your crate.

RUSTC BOOK

Familiarize yourself with the knobs available in the Rust compiler.

COMPILER ERROR INDEX

In-depth explanations of the errors you may see from the Rust compiler.

Build your skills in an application domain

COMMAND LINE BOOK

Learn how to build effective command line applications in Rust.

WEBASSEMBLY BOOK

Use Rust to build browser-native libraries through WebAssembly.

EMBEDDED BOOK

Become proficient with Rust for Microcontrollers and other embedded systems.

Master Rust

The Reference is not a formal spec, but is more detailed and comprehensive than the book.
 

The Rustonomicon is your guidebook to the dark arts of unsafe Rust. It’s also sometimes called “the ’nomicon.”

READ THE ’NOMICON

 

The Unstable Book has documentation for unstable features that you can only use with nightly Rust.

READ THE UNSTABLE BOOK

 

rust web framework comparison

comparison

rust python example

awesome

awesome rust  (CN)

awesome c(CN)

awesome python

debugger

gdbgui

debug-here

cargo install debug-here-gdb-wrapper # if you are on linux
cd debug-here/debug-me
echo | sudo tee /proc/sys/kernel/yama/ptrace_scope
cargo run 
# In Cargo.toml.

[dependencies]
debug-here = "0.2" # in source file. Now it looks like this: #[macro_use] extern crate debug_here; fn factorial(n: usize) -> usize {
let mut res = ;
debug_here!(); }

config xterm (EN) (CN) (wiki)

cat ~/.Xresources

config as follow:

 ! Use a nice truetype font and size by default...
xterm*faceName: DejaVu Sans Mono Book
xterm*faceSize: ! Every shell is a login shell by default (for inclusion of all necessary environment variables)
xterm*loginshell: true ! I like a LOT of scrollback...
xterm*savelines: ! double-click to select whole URLs :D
xterm*charClass: :,-:,-:,:,-:,:,: ! DOS-box colours...
xterm*foreground: rgb:a8/a8/a8
xterm*background: rgb://
xterm*color0: rgb://
xterm*color1: rgb:a8//
xterm*color2: rgb:/a8/
xterm*color3: rgb:a8//
xterm*color4: rgb://a8
xterm*color5: rgb:a8//a8
xterm*color6: rgb:/a8/a8
xterm*color7: rgb:a8/a8/a8
xterm*color8: rgb://
xterm*color9: rgb:fc//
xterm*color10: rgb:/fc/
xterm*color11: rgb:fc/fc/
xterm*color12: rgb://fc
xterm*color13: rgb:fc//fc
xterm*color14: rgb:/fc/fc
xterm*color15: rgb:fc/fc/fc ! right hand side scrollbar...
xterm*rightScrollBar: true
xterm*ScrollBar: true ! stop output to terminal from jumping down to bottom of scroll again
xterm*scrollTtyOutput: false

Tell your X server to incorporate those tweak

xrdb -merge ~/.Xresources

debug test case

How do I debug a failing cargo test in gdb?

Ask GDB to list all functions in a program

info functions
info functions regexp

16 Examining the Symbol Table    (16 Examining the Symbol Table.)

Debugging Rust Tests

rust-gdb /vagrant/target/debug/deps/libzfs-37d0dad38d98d030
b lib.rs:
run --test

How do I debug a failing cargo test in GDB?

debug info

 $ cargo test --lib
Finished dev [unoptimized + debuginfo] target(s) in .03s
Running target/debug/deps/hello_cargo-b786631aa108fec0 running tests
test tests::it_works ... ok
test tests::test_add ... ok
test tests::test_bad_add ... FAILED failures: ---- tests::test_bad_add stdout ----
thread 'tests::test_bad_add' panicked at 'assertion failed: `(left == right)`
left: `-`,
right: ``', src/lib.rs:32:9
note: Run with `RUST_BACKTRACE=` environment variable to display a backtrace. failures:
tests::test_bad_add test result: FAILED. passed; failed; ignored; measured; filtered out error: test failed, to rerun pass '--lib' $ rust-gdb target/debug/deps/hello_cargo-b786631aa108fec0
GNU gdb (Ubuntu 7.11.-0ubuntu1~16.5) 7.11.
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from target/debug/deps/hello_cargo-b786631aa108fec0...done.
(gdb) info functions test_bad_add
All functions matching regular expression "test_bad_add": File src/lib.rs:
static void hello_cargo::tests::test_bad_add::_$u7b$$u7b$closure$u7d$$u7d$::hacffd70b508c276a(struct closure *);
static void hello_cargo::tests::test_bad_add::h938c2acc2927d730(void);
(gdb) b hello_cargo::tests::test_bad_add::h938c2acc2927d730
Breakpoint at 0x139f7: file src/lib.rs, line .
(gdb) run --test test_bad_add
Starting program: /home/shhfeng/test/hello_cargo/target/debug/deps/hello_cargo-b786631aa108fec0 --test test_bad_add
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". running test
[New Thread 0x7ffff6ec4700 (LWP )]
[Switching to Thread 0x7ffff6ec4700 (LWP )] Thread "tests::test_bad" hit Breakpoint , hello_cargo::tests::test_bad_add::h938c2acc2927d730 () at src/lib.rs:
assert_eq!(bad_add(, ), );
(gdb) list
} #[test]
fn test_bad_add() {
// 这个断言会导致测试失败。注意私有的函数也可以被测试!
assert_eq!(bad_add(, ), );
}
}
(gdb) s
hello_cargo::bad_add::h460b365704f64b13 (a=, b=) at src/lib.rs:

debug detail

 (gdb) bt
# hello_cargo::bad_add::h460b365704f64b13 (a=, b=) at src/lib.rs:
# 0x0000555555567a06 in hello_cargo::tests::test_bad_add::h938c2acc2927d730 () at src/lib.rs:
# 0x00005555555676ea in hello_cargo::tests::test_bad_add::_$u7b$$u7b$closure$u7d$$u7d$::hacffd70b508c276a () at src/lib.rs:
# 0x000055555556754e in core::ops::function::FnOnce::call_once::h859d77482d101f3d ()
at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libcore/ops/function.rs:
# 0x000055555557005f in {{closure}} () at src/libtest/lib.rs:
# call_once<closure,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libcore/ops/function.rs:
# call_box<(),closure> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/liballoc/boxed.rs:
# 0x00005555555b3fda in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:
# 0x000055555558d168 in try<(),std::panic::AssertUnwindSafe<alloc::boxed::Box<FnBox<()>>>> ()
at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panicking.rs:
# catch_unwind<std::panic::AssertUnwindSafe<alloc::boxed::Box<FnBox<()>>>,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panic.rs:
# {{closure}} () at src/libtest/lib.rs:
# 0x00005555555688a5 in std::sys_common::backtrace::__rust_begin_short_backtrace::h7988d0d59efc7a12 ()
at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/sys_common/backtrace.rs:
# 0x0000555555569045 in {{closure}}<closure,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/thread/mod.rs:
# call_once<(),closure> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panic.rs:
# do_call<std::panic::AssertUnwindSafe<closure>,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panicking.rs:
# 0x00005555555b3fda in __rust_maybe_catch_panic () at src/libpanic_unwind/lib.rs:
# 0x000055555557018d in try<(),std::panic::AssertUnwindSafe<closure>> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panicking.rs:
# catch_unwind<std::panic::AssertUnwindSafe<closure>,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/panic.rs:
# {{closure}}<closure,()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libstd/thread/mod.rs:
# call_box<(),closure> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/liballoc/boxed.rs:
# 0x00005555555b371e in call_once<(),()> () at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/liballoc/boxed.rs:
# start_thread () at src/libstd/sys_common/thread.rs:
# thread_start () at src/libstd/sys/unix/thread.rs:
# 0x00007ffff77b56ba in start_thread (arg=0x7ffff6ec4700) at pthread_create.c:
# 0x00007ffff72d541d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:

rust debugger

Vebugger

Debugging Rust code with vim and Conque-GDB

# install  Vundle firstl list then vimproc.vim
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Plugin 'vim-scripts/Conque-GDB'
# in vim, :PluginInstall , :ConqueGdbExe rust-gdb , :ConqueGdb target/debug/$name

plugin

github

doc

BKM:

Vim插件之Conque GDB

How can I integrate gdb with Vim?

Using ConqueGDB to debug ARM microcontroller with OpenOCD

vimproc.vim

Vundle.vim

如何在vim中可视化的调试c++程序?

Vim与GCC和gdb完美组合

 

vi/vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb (vimgdb)

rust-gdb/rust-lldb (github)

debugging-rust-with-gdb

rustc -g main.rs --emit="obj,link"
gdb main # created two aliases for my bash to make things simple: alias rd='rustc -g --emit="obj,link"' compile_and_run() {
rustc -g --emit="obj,link" $ && gdb ${%.*}
} alias rdr=compile_and_run

REPL

Rusti

# Link failure: cannot find -lncursesw  https://github.com/murarth/rusti/issues/92
sudo apt-get install libncursesw5-dev
# completion https://github.com/racer-rust/racer#installation
rustup toolchain add nightly
cargo +nightly install racer
export PATH="$PATH:$HOME/.cargo/bin"
rustup install nightly-2016-08-01
rustup run nightly-2016-08-01 cargo install --git https://github.com/murarth/rusti
# https://github.com/murarth/rusti/issues/90 error while loading shared libraries: librustc_driver-c8005792.so
rustup run nightly-2016-08-01 ~/.cargo/bin/rusti
rustup run nightly-2016-08-01 target/debug/rusti

IDE

Rust Language Server (RLS)

edition

Rustup for managing Rust versions

Tips

1. 调试宏代码

rustc --pretty expanded

2. Rust进阶之条件编译

#[cfg(foo)]
#[cfg(bar = "baz")] #[cfg(any(unix, windows))]
#[cfg(all(unix, target_pointer_width = ""))]
#[cfg(not(foo))]

official example

offical doc

Gramma

1. PhantomData

Doc: try by size_of

#![allow(unused)]
use std::marker::PhantomData;
use std::mem; fn main() {
#[allow(dead_code)]
struct Slice<'a, T: 'a> {
start: *const T,
end: *const T,
phantom: PhantomData<&'a T>,
} struct Slice1<T:> {
start: *const T,
end: *const T,
} println!("{:?}", mem::size_of::<Slice<i32>>());
println!("{:?}", mem::size_of::<Slice1<i32>>());
} // output:
// 16
// 16

2. Vec.with_capacity

Doc

3. typyof by type_name

base type of rust from Reference Doc

#![feature(core_intrinsics)]
use std::mem; fn print_type_of<T>(_: &T) {
println!("{}", unsafe { std::intrinsics::type_name::<T>() });
} fn main() {
print_type_of(&32.90); // prints "f64"
print_type_of(&vec![1, 2, 4]); // prints "std::vec::Vec<i32>"
print_type_of(&"foo"); // prints "&str"
let ln = mem::size_of::<i32>() as u64;
print_type_of(&ln) // prints "u64"
}

4. 错误处理(match, let and ? 用法)

Doc

Result is a good example.  

5. 闭包

Closures

6. Option

map_or and related

简易教程:

易百教程 

极客学院:

slice宏定义, Option, 迭代器

rust 写一个操作系统 

rust学习的更多相关文章

  1. Rust学习资源和路线

    Rust学习资源和路线 来源 https://rust-lang-cn.org/article/23 学习资源 The Rust Programming Language 堪称Rust的"T ...

  2. 【译】通过 Rust 学习解析器组合器 — Part 1

    原文地址:Learning Parser Combinators With Rust 原文作者:Bodil 译文出自:掘金翻译计划 本文永久链接:https://github.com/xitu/gol ...

  3. [追热点]Rust学习资源整理

    为什么选择Rust 在一次演讲中,谈到微软为解决相应内存问题所做的工作,微软研究人员 Matthew Parkinson 提到了微软正在开发的基于 Rust 的新编程语言 Verona. 摘自:[Ru ...

  4. Rust学习-阶段1学习总结

    学习Rust已经两周了,基本上是断断续续的在学,或者是在上下班坐公交时,或者是在ODC没事做时.现在已经学习了Rust程序设计语言的前5章,是时候做一个总结了.关于数据类型或者if else这种内容我 ...

  5. rust学习小记(1)

    本文的学习资料来自 Rust 程序设计语言 简体中文版 推荐用idea来写rust,装好插件rust和toml即可 cargo(包管理) 可以使用 cargo build 或 cargo check  ...

  6. Rust学习笔记1

    这是一份不错的rust教程,目前包括4个block和4个project.全部完成后可以用rust实现一个简单的key-value存储引擎. 注意:Windows下rust貌似会遇到一些bug,强烈建议 ...

  7. Rust学习笔记一 数据类型

    写在前面 我也不是什么特别厉害的大牛,学历也很低,只是对一些新语言比较感兴趣,接触过的语言不算多也不算少,大部分也都浅尝辄止,所以理解上可能会有一些偏差. 自学了Java.Kotlin.Python. ...

  8. Rust学习(一)

    为什么学习Rust 最近在看Linux相关新闻的时候,看到了Linux内核正在将Rust集成至内核内的消息,且越来越多的嵌入式开发可以使用Rust编程.以往笔者的技术栈只有 C语言 ,C++也只是浅尝 ...

  9. Rust 学习 0

    安装Rust 后,本地有文档: file:///usr/local/share/doc/rust/html/index.html file:///usr/local/share/doc/rust/ht ...

  10. rust学习(二)

    play on line match if #![allow(unused)] fn write_bar(size: u64){ match size{ o => println!(" ...

随机推荐

  1. SQL Server 2012启动时提示:无效的许可证数据,需要重新安装

    因为手咸,觉得电脑没有VS 2010版本的软件,就把Microsoft Visual C++ 2010某个组件给卸载了. 然后打开Sql Server 2012,就开始报错. 重装之后,也还是报错,将 ...

  2. c# 基于WebApi的快速开发框架FastFramework

    一.框架简介 此框架是针对于webapi进行开发,项目分层是基于ABP框架的分层,更好的抽离业务逻辑关系,ABP是基于EF做数据访问层,本人个人比较喜欢Dapper,就把数据访问层封装成了Dapper ...

  3. C#使用Autofac实现控制反转IoC和面向切面编程AOP

    Autofac是一个.net下非常优秀,性能非常好的IOC容器(.net下效率最高的容器),加上AOP简直是如虎添翼.Autofac的AOP是通过Castle(也是一个容器)项目的核心部分实现的,名为 ...

  4. python3 语法 数据类型

     python3中 有6种标准数据类型 数字,字符串,列表,元祖,集合,字典

  5. 必须掌握的Linux用户组知识

    在 Linux 系统中用户组起着重要作用.用户组提供了一种简单方法供一组用户互相共享文件.用户组也允许系统管理员更加有效地管理用户权限,因为管理员可以将权限分配给用户组而不是逐一分配给单个用户. 尽管 ...

  6. 软件平台ThinkSNS+软件系统研发日记

    NO.1: 实用开源软件安装部署是第一步, ThinkSNS+响应快速安装,易于二开基准,为大家录制了一份宝塔面板安装社交系统ThinkSNS+视频教程,点开观看视频一起吸一吸. 若无法播放,请直接打 ...

  7. Mysql中use filesort的误区

    误区一字面误区 use filesort排序,字面上理解是外部排序. 误区二人云亦云 百度上多被大家否定不是外部排序,认为和file这个关键字没关系.用的是快速排序.但是总觉得不可能这么无缘无故叫fi ...

  8. 彻底弄懂ES6中的Map和Set

    Map Map对象保存键值对.任何值(对象或者原始值) 都可以作为一个键或一个值.构造函数Map可以接受一个数组作为参数. Map和Object的区别 一个Object 的键只能是字符串或者 Symb ...

  9. Appscan漏洞 之 加密会话(SSL)Cookie 中缺少 Secure 属性

    近期 Appscan扫描出漏洞 加密会话(SSL)Cookie 中缺少 Secure 属性,已做修复,现进行总结如下: 1.1.攻击原理 任何以明文形式发送到服务器的 cookie.会话令牌或用户凭证 ...

  10. Mysql慢查询日志以及优化

    慢查询日志设置 当语句执行时间较长时,通过日志的方式进行记录,这种方式就是慢查询的日志. 1.临时开启慢查询日志(如果需要长时间开启,则需要更改mysql配置文件) set global slow_q ...