Added chapters 1 and 8
parent
c45e5ce487
commit
13c7dc4081
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "bench-test"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "bench-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,27 @@
|
|||||||
|
#![feature(test)]
|
||||||
|
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
pub fn get_fact(n: u64) -> u64 {
|
||||||
|
if n < 2 {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
n * get_fact(n - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(120, get_fact(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_get_fact(b: &mut Bencher) {
|
||||||
|
b.iter(|| get_fact(1234571));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,82 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
|
||||||
|
dependencies = [
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dep-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.42"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.1.43"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "dep-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "*"
|
@ -0,0 +1,5 @@
|
|||||||
|
use chrono as time;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, time now is {:?}", time::Utc::now());
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "feature-test"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "feature-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "featuretest"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
feature1 = []
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,19 @@
|
|||||||
|
#[cfg(feature = "feature1")]
|
||||||
|
pub use self::with_feature_config::execute;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "feature1"))]
|
||||||
|
pub use self::without_feature_config::execute;
|
||||||
|
|
||||||
|
#[cfg(feature = "feature1")]
|
||||||
|
mod with_feature_config {
|
||||||
|
pub fn execute() {
|
||||||
|
println!("Executing feature 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "feature1"))]
|
||||||
|
mod without_feature_config {
|
||||||
|
pub fn execute() {
|
||||||
|
println!("Not executing feature 1")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
use feature_test::execute;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
execute();
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "first-program"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "first-program"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "new-first-program"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "new-second-program"
|
||||||
|
path = "src/second.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello for the second time!")
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "integ-test-example"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "integ-test-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,42 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta name="generator" content="rustdoc">
|
||||||
|
<title>Docs for integ-test-example crate</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="rustdoc">
|
||||||
|
<!--[if lte IE 8]>
|
||||||
|
<div class="warning">
|
||||||
|
This old browser is unsupported and will most likely display funky
|
||||||
|
things.
|
||||||
|
</div>
|
||||||
|
<![endif]-->
|
||||||
|
|
||||||
|
|
||||||
|
<h1 class="title">Docs for integ-test-example crate</h1>
|
||||||
|
<nav id="TOC"><ul>
|
||||||
|
<li><a href="#function-signature">0.1 Function signature</a><ul></ul></li>
|
||||||
|
<li><a href="#example">0.2 Example</a><ul></ul></li></ul></nav><p>This is a project to test <code>rustdoc</code>.</p>
|
||||||
|
<p><a href="https://www.rust-lang.org">Here is a link!</a></p>
|
||||||
|
<h2 id="function-signature" class="section-header"><a href="#function-signature">0.1 Function signature</a></h2>
|
||||||
|
<p>pub fn get_process_id() -> u32 {}</p>
|
||||||
|
<p>This function returns the process id of the current running executable</p>
|
||||||
|
<h2 id="example" class="section-header"><a href="#example">0.2 Example</a></h2>
|
||||||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||||
|
|
||||||
|
<span class="kw">use</span> <span class="ident">integ_test_example</span>;
|
||||||
|
|
||||||
|
<span class="kw">fn</span> <span class="ident">get_id</span>() <span class="op">-</span><span class="op">></span> <span class="ident">i32</span> {
|
||||||
|
<span class="kw">let</span> <span class="ident">my_pid</span> <span class="op">=</span> <span class="ident">get_process_id</span>();
|
||||||
|
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Process id for current process is: {}"</span>, <span class="ident">my_pid</span>);
|
||||||
|
}
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,24 @@
|
|||||||
|
# Docs for integ-test-example crate
|
||||||
|
|
||||||
|
This is a project to test `rustdoc`.
|
||||||
|
|
||||||
|
[Here is a link!](https://www.rust-lang.org)
|
||||||
|
|
||||||
|
## Function signature
|
||||||
|
|
||||||
|
pub fn get_process_id() -> u32 {}
|
||||||
|
|
||||||
|
This function returns the process id of the current running executable
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```rust
|
||||||
|
|
||||||
|
use integ_test_example;
|
||||||
|
|
||||||
|
fn get_id() {
|
||||||
|
let my_pid = get_process_id();
|
||||||
|
println!("Process id for current process is: {}", my_pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
//! Integration-test-example crate
|
||||||
|
//!
|
||||||
|
//! This is a library that contains functions related to dealing with processes
|
||||||
|
//! , and makes these tasks more convenient.
|
||||||
|
|
||||||
|
use std::process;
|
||||||
|
/// This function gets the process id of the current executable. It returns a non-zero number
|
||||||
|
/// ```
|
||||||
|
/// fn get_id() {
|
||||||
|
/// let x = integ_test_example::get_process_id();
|
||||||
|
/// println!("{}",x);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn get_process_id() -> u32 {
|
||||||
|
process::id()
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
use integ_test_example;
|
||||||
|
#[test]
|
||||||
|
fn files_test1() {
|
||||||
|
assert_ne!(integ_test_example::get_process_id(), 0, "Error in code");
|
||||||
|
}
|
||||||
|
/* Hello this is a multiline
|
||||||
|
* comment
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Hello this is a single line comment
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn files_test2() {
|
||||||
|
assert_eq!(1 + 1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn process_test1() {
|
||||||
|
assert!(true);
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "my-first-lib"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "my-first-lib"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mymain"
|
||||||
|
path = "src/mymain.rs"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,12 @@
|
|||||||
|
pub fn hello_from_lib(message: & str) {
|
||||||
|
println!("Printing Hello {} from library",message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
use my_first_lib::hello_from_lib;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Going to call library function");
|
||||||
|
hello_from_lib("Rust system programmer");
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "test-example"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "test-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,19 @@
|
|||||||
|
use std::process;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", get_process_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_process_id() -> u32 {
|
||||||
|
process::id()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::get_process_id;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_process_id_is_returned() {
|
||||||
|
assert_ne!(get_process_id(), 0, "There is error in code");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
use my-process-lib;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_if_process_id_is_returned() {
|
||||||
|
assert_eq!(get_process_id(), 0, "There is error in code");
|
||||||
|
println!("Hello from integration test")
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,40 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "arc-swap"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.77"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sec1"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"signal-hook",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook"
|
||||||
|
version = "0.1.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"signal-hook-registry",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035"
|
||||||
|
dependencies = [
|
||||||
|
"arc-swap",
|
||||||
|
"libc",
|
||||||
|
]
|
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "sec1"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["peshwar9 <par.esh1937@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
signal-hook = "0.1.16"
|
@ -0,0 +1 @@
|
|||||||
|
Hello world
|
@ -0,0 +1,6 @@
|
|||||||
|
Cargo.lock
|
||||||
|
Cargo.toml
|
||||||
|
a.txt
|
||||||
|
b.txt
|
||||||
|
src
|
||||||
|
target
|
@ -0,0 +1,37 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
use std::io::{stdin, stdout};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
loop {
|
||||||
|
print!("$");
|
||||||
|
stdout().flush().unwrap();
|
||||||
|
let mut user_input = String::new();
|
||||||
|
stdin()
|
||||||
|
.read_line(&mut user_input)
|
||||||
|
.expect("Unable to read user input");
|
||||||
|
let command_to_execute = user_input.trim();
|
||||||
|
let command_args: Vec<&str> = command_to_execute.split_whitespace().collect();
|
||||||
|
let mut child = match command_args[0] {
|
||||||
|
"show" => match command_args[1] {
|
||||||
|
"files" => Command::new("ls")
|
||||||
|
.args(&command_args[2..])
|
||||||
|
.spawn()
|
||||||
|
.expect("Unable to execute command"),
|
||||||
|
"process" => Command::new("ps")
|
||||||
|
.args(&command_args[2..])
|
||||||
|
.spawn()
|
||||||
|
.expect("Unable to execute command"),
|
||||||
|
_ => Command::new("pwd")
|
||||||
|
.args(&command_args[2..])
|
||||||
|
.spawn()
|
||||||
|
.expect("Unable to execute command"),
|
||||||
|
},
|
||||||
|
_ => Command::new(command_args[0])
|
||||||
|
.args(&command_args[1..])
|
||||||
|
.spawn()
|
||||||
|
.expect("Unable to execute command"),
|
||||||
|
};
|
||||||
|
child.wait().unwrap();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue