Skip to content

Commit

Permalink
源码上传
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousGiga committed Jan 26, 2020
0 parents commit a2741ef
Show file tree
Hide file tree
Showing 395 changed files with 4,254 additions and 0 deletions.
13 changes: 13 additions & 0 deletions addr/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions addr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"adder",
"add-one",
]
3 changes: 3 additions & 0 deletions addr/add-one/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock
9 changes: 9 additions & 0 deletions addr/add-one/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "add-one"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
11 changes: 11 additions & 0 deletions addr/add-one/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub fn add_one(x: i32) -> i32 {
x + 1
}

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
2 changes: 2 additions & 0 deletions addr/adder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
10 changes: 10 additions & 0 deletions addr/adder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
add-one = {path = "../add-one"}
8 changes: 8 additions & 0 deletions addr/adder/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use add_one;

fn main() {
let num = 10;
let r = add_one::add_one(num);
println!("r === {}", r);
println!("Hello, world!");
}
1 change: 1 addition & 0 deletions addr/target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":17989264669760749350,"outputs":{"1164083562126845933":["rustc 1.38.0 (625451e37 2019-09-23)\nbinary: rustc\ncommit-hash: 625451e376bb2e5283fc4741caa0a3e8a2ca4d54\ncommit-date: 2019-09-23\nhost: x86_64-unknown-linux-gnu\nrelease: 1.38.0\nLLVM version: 9.0\n",""],"1138116330425514636":["___\n",""],"4476964694761187371":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/andy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"2196823701345282402":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/andy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""]},"successes":{}}
Empty file added addr/target/debug/.cargo-lock
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4691ba37eeb80a4a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":10683586082858123265,"features":"[]","target":3349314055383906947,"profile":14996655781355331481,"path":652465830340624038,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/add-one-f25b03445ef13e1f/dep-lib-add_one-f25b03445ef13e1f"}}],"rustflags":[],"metadata":15972075885573944569}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
96d607c8f7968f34
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":10683586082858123265,"features":"[]","target":9805538687745692616,"profile":14996655781355331481,"path":7714536825948459707,"deps":[[9496724924318511037,"add_one",false,5335280041850474822]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adder-309a7669209f2ef8/dep-bin-adder-309a7669209f2ef8"}}],"rustflags":[],"metadata":15972075885573944569}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
650e2d912115d760
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":10683586082858123265,"features":"[]","target":9805538687745692616,"profile":14996655781355331481,"path":7714536825948459707,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adder-dbdfdc450c2d3728/dep-bin-adder-dbdfdc450c2d3728"}}],"rustflags":[],"metadata":15972075885573944569}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Binary file added addr/target/debug/adder
Binary file not shown.
1 change: 1 addition & 0 deletions addr/target/debug/adder.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/andy/source/rust/learn_rust/addr/target/debug/adder: /home/andy/source/rust/learn_rust/addr/add-one/src/lib.rs /home/andy/source/rust/learn_rust/addr/adder/src/main.rs
7 changes: 7 additions & 0 deletions addr/target/debug/deps/add_one-f25b03445ef13e1f.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/home/andy/source/rust/learn_rust/addr/target/debug/deps/add_one-f25b03445ef13e1f.rmeta: add-one/src/lib.rs

/home/andy/source/rust/learn_rust/addr/target/debug/deps/libadd_one-f25b03445ef13e1f.rlib: add-one/src/lib.rs

/home/andy/source/rust/learn_rust/addr/target/debug/deps/add_one-f25b03445ef13e1f.d: add-one/src/lib.rs

add-one/src/lib.rs:
Binary file added addr/target/debug/deps/adder-309a7669209f2ef8
Binary file not shown.
5 changes: 5 additions & 0 deletions addr/target/debug/deps/adder-309a7669209f2ef8.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/home/andy/source/rust/learn_rust/addr/target/debug/deps/adder-309a7669209f2ef8: adder/src/main.rs

/home/andy/source/rust/learn_rust/addr/target/debug/deps/adder-309a7669209f2ef8.d: adder/src/main.rs

adder/src/main.rs:
Binary file added addr/target/debug/deps/adder-dbdfdc450c2d3728
Binary file not shown.
5 changes: 5 additions & 0 deletions addr/target/debug/deps/adder-dbdfdc450c2d3728.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/home/andy/source/rust/learn_rust/addr/target/debug/deps/adder-dbdfdc450c2d3728: adder/src/main.rs

/home/andy/source/rust/learn_rust/addr/target/debug/deps/adder-dbdfdc450c2d3728.d: adder/src/main.rs

adder/src/main.rs:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions addr/target/debug/libadd_one.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/andy/source/rust/learn_rust/addr/target/debug/libadd_one.rlib: /home/andy/source/rust/learn_rust/addr/add-one/src/lib.rs
Binary file added addr/target/debug/libadd_one.rlib
Binary file not shown.
2 changes: 2 additions & 0 deletions hello/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
6 changes: 6 additions & 0 deletions hello/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "hello"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
2 changes: 2 additions & 0 deletions learn_T/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
6 changes: 6 additions & 0 deletions learn_T/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions learn_T/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "learn_T"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
137 changes: 137 additions & 0 deletions learn_T/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//1、泛型是具体类型或者其它属性的抽象替代,用于减少代码重复.
//2、在函数定义中使用泛型。
//3、在结构体中使用泛型。
//4、枚举中的泛型。
//5、方法中的泛型。
//6、总结:使用泛型并不会造成程序性能上的损失。rust通过在编译时进行泛型代码的单态化来保证效率。单态化时通过填充编译时使用的具体类型,将通用代码转换为特定代码的过程。
////--------没有泛型-----------
////for i32
//fn largest_i32(list: &[i32]) -> i32 {
// let mut largest = list[0];
// for &item in list.iter() {
// if item > largest {
// largest = item;
// }
// }
//
// largest
//}
//
////for char
//fn largest_char(list: &[char]) -> char {
// let mut largest = list[0];
// for &item in list.iter() {
// if item > largest {
// largest = item;
// }
// }
//
// largest
//}

////----------使用泛型-------------
//fn largest<T: PartialOrd + Copy> (list: &[T]) -> T {
// let mut larger = list[0];
// for &item in list.iter() {
// if item > larger {
// larger = item;
// }
// }
// larger
//}
//
//fn main() {
// let number_list = vec![1, 2, 23, 34, 8, 100];
// //let max_number = largest_i32(&number_list);
// let max_number = largest(&number_list);
// println!("max_number = {}", max_number);
//
// let char_list= vec!['a', 'y', 'b'];
// //let max_char = largest_char(&char_list);
// let max_char = largest(&char_list);
// println!("max_char = {}", max_char);
// println!("Hello, world!");
//}


////------在结构体中使用泛型--------
//#[derive(Debug)]
//struct Point<T> {
// x: T,
// y: T,
//}
//
//#[derive(Debug)]
//struct Point2<T, U> {
// x: T,
// y: U,
//}
//
//fn main() {
// let integer = Point{x: 1, y: 2};
// println!("{:#?}", integer);
//
// let float = Point{x: 1.1, y: 2.2};
// println!("{:?}", float);
//
// let a = Point2{x: 1.1, y: 'a'};
// println!("a = {:?}", a);
//}
//
////----------在枚举中使用泛型------------
//enum Option<T> {
// Some(T),
// None,
//}
//
//enum Result<T, E> {
// Ok(T),
// Err(E)
//}
////----------------------------------------

//-----------在方法中使用泛型--------------
struct Point<T> {
x: T,
y: T,
}

impl<T> Point<T> {
fn get_x(&self) -> &T {
&self.x
}

fn get_y(&self) -> &T {
&self.y
}
}

struct Point2<T, U> {
x: T,
y: U,
}

impl<T, U> Point2<T, U> {
fn creat_point<V, W>(self, other: Point2<V, W>) -> Point2<T, W> {
Point2 {
x: self.x,
y: other.y,
}
}
}


fn main() {
let p = Point{x:1, y: 2};
println!("x = {}", p.get_x());
println!("y = {}", p.get_y());

let p = Point{x:1.1, y: 2.2};
println!("x = {}", p.get_x());
println!("y = {}", p.get_y());

let p1 = Point2{x: 5, y: 1.1};
let p2 = Point2{x: "hello", y: 'c'};
let p3 = p1.creat_point(p2);
println!("p3.x = {}, p3.y = {}", p3.x, p3.y);
}
2 changes: 2 additions & 0 deletions learn_box/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
6 changes: 6 additions & 0 deletions learn_box/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions learn_box/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "learn_box"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
11 changes: 11 additions & 0 deletions learn_box/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//1、最简单最直接的智能指针是box,其类型为Box<T>。box允许将值放在堆上而不是栈上,留着栈上的则是指向堆数据的指针。除了数据被存储在堆上外,box没有任何性能损失。
//
//2、box适合用于如下场景:
//(1)当有一个在编译时未知大小的类型,而又需要再确切大小的上下文中使用这个类型值的时候;(举例子:在一个list环境下,存放数据,但是每个元素的大小在编译时又不确定)
//(2)当有大量数据并希望在确保数据不被拷贝的情况下转移所有权的时候;
//(3)当希望拥有一个值并只关心它的类型是否实现了特定trait而不是其具体类型时。
fn main() {
let b = Box::new(5); //b存储于栈上,5存储在堆上,b指向5所在的内存
println!("b = {}", b);
println!("Hello, world!");
}
2 changes: 2 additions & 0 deletions learn_box1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
6 changes: 6 additions & 0 deletions learn_box1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions learn_box1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "learn_box1"
version = "0.1.0"
authors = ["andy"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
32 changes: 32 additions & 0 deletions learn_box1/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//box适合用于如下场景:
//(1)当有一个在编译时未知大小的类型,而又需要再确切大小的上下文中使用这个类型值的时候;(举例子:在一个list环境下,存放数据,但是每个元素的大小在编译时又不确定)
//(2)当有大量数据并希望在确保数据不被拷贝的情况下转移所有权的时候;
//(3)当希望拥有一个值并只关心它的类型是否实现了特定trait而不是其具体类型时。
//enum List {
// Cons(i32, List),
// Nil,
//}

enum List {
Cons(i32, Box<List>),
Nil,
}

//struct List {
// int value;
// struct List *next;
// //struct List l;
//};

//
fn main() {
use List::Cons;
use List::Nil;
//let list = Cons(1, Cons(2, Cons(3, Nil)));

let list = Cons(1,
Box::new(Cons(2,
Box::new(Cons(3,
Box::new(Nil))))));
println!("Hello, world!");
}
2 changes: 2 additions & 0 deletions learn_cargo1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
6 changes: 6 additions & 0 deletions learn_cargo1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a2741ef

Please sign in to comment.