├── 9781484255988.jpg ├── Contributing.md ├── LICENSE.txt ├── README.md ├── cli └── catsay │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── cat_1.txt │ ├── src │ ├── bench.rs │ └── main.rs │ └── tests │ └── integration_test.rs ├── errata.md ├── game └── cat_volleyball │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── assets │ ├── audio │ │ ├── Computer_Music_All-Stars_-_Albatross_v2.ogg │ │ ├── Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg │ │ ├── LICENSE_AUDIO.txt │ │ ├── boop.ogg │ │ ├── bounce.ogg │ │ ├── confirm.ogg │ │ └── score.ogg │ ├── font │ │ └── square.ttf │ └── texture │ │ ├── ball.png │ │ ├── ball_color.png │ │ ├── pixel-cat.png │ │ ├── pixel-cat_flipped.png │ │ ├── spritesheet.json │ │ ├── spritesheet.png │ │ └── spritesheet.ron │ ├── audio │ ├── Computer_Music_All-Stars_-_Albatross_v2.ogg │ ├── Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg │ ├── LICENSE_AUDIO.txt │ ├── bounce.ogg │ └── score.ogg │ ├── font │ └── square.ttf │ ├── resources │ ├── bindings_config.ron │ └── display_config.ron │ ├── src │ ├── audio.rs │ ├── catvolleyball.rs │ ├── main.rs │ └── systems │ │ ├── bounce.rs │ │ ├── mod.rs │ │ ├── move_balls.rs │ │ ├── player.rs │ │ └── winner.rs │ └── texture │ ├── spritesheet.png │ └── spritesheet.ron ├── gui ├── catsay-gui-glade │ ├── Cargo.lock │ ├── Cargo.toml │ ├── images │ │ ├── cat.png │ │ └── cat_dead.png │ └── src │ │ ├── #layout.glade# │ │ ├── cat.png │ │ ├── layout.glade │ │ ├── layout.glade~ │ │ ├── main.rs │ │ └── main.rs.bk ├── catsay-gui │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── images │ │ └── cat.png │ ├── layout.glade │ └── src │ │ └── main.rs └── catsay-tui │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ └── src │ └── main.rs ├── machine-learning ├── cat-breed-k-means │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── cat_breed.md │ ├── config │ │ ├── generate.toml │ │ └── generate2.toml │ ├── run.sh │ └── src │ │ ├── bin │ │ ├── cluster.rs │ │ ├── generate.rs │ │ ├── plot.rs │ │ └── plot_results.rs │ │ └── main.rs └── cat-or-dog-nnet │ ├── Cargo.lock │ ├── Cargo.toml │ ├── run.sh │ └── src │ └── bin │ ├── generate_data.rs │ └── train_and_predict.rs └── physical ├── blink-cross-compile ├── Cargo.lock ├── Cargo.toml ├── auto-blink ├── button_debounce ├── manual-blink └── src │ └── main.rs └── physical-computing ├── Cargo.lock ├── Cargo.toml ├── examples ├── auto-blink.rs ├── button-debounce.rs ├── button.rs ├── led-on.rs └── manual-blink.rs └── sysfs.sh /9781484255988.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/9781484255988.jpg -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2020 Shing Lyu 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*%Practical Rust Projects%*](https://www.apress.com/9781484255988) by Shing Lyu (Apress, 2020). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484255988.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /cli/catsay/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "catsay" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | structopt = "0.3.5" 9 | colored = "1.7.0" 10 | failure = "0.1.5" 11 | exitfailure = "0.5.1" 12 | assert_cmd = "0.11.1" 13 | predicates = "1.0.0" 14 | -------------------------------------------------------------------------------- /cli/catsay/README.md: -------------------------------------------------------------------------------- 1 | ## Testing stdout and stderr 2 | 3 | ``` 4 | cargo run "woof" 1> stdout.txt 2> stderr.txt 5 | ``` 6 | -------------------------------------------------------------------------------- /cli/catsay/cat_1.txt: -------------------------------------------------------------------------------- 1 | \ 2 | \ / ) 3 | \ (\__/) ( ( 4 | ){eye} {eye} ( ) ) 5 | ={ Y }= / / 6 | ) `-------/ / 7 | ( / 8 | \ | 9 | ,'\ , ,' 10 | `-'\ ,---\ | \ 11 | _) ) `. \ / 12 | (__/ ) ) 13 | (_/ 14 | -------------------------------------------------------------------------------- /cli/catsay/src/bench.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | #[cfg(test)] 4 | mod tests { 5 | #[bench] 6 | fn bench_main_1000_times() { 7 | for _ in 0..1000 { 8 | main::main() 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /cli/catsay/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate colored; 2 | extern crate structopt; 3 | 4 | use colored::*; 5 | use exitfailure::ExitFailure; 6 | use failure::ResultExt; 7 | use std::io::{self, Read, Write}; 8 | use structopt::StructOpt; 9 | 10 | #[derive(StructOpt)] 11 | struct Options { 12 | #[structopt(short = "i", long = "stdin")] 13 | /// Read the message from STDIN instead of the argument 14 | stdin: bool, 15 | 16 | #[structopt(default_value = "Meow!")] 17 | /// What does the cat say? 18 | message: String, 19 | 20 | #[structopt(short = "f", long = "file", parse(from_os_str))] 21 | /// Load the cat picture from the specified file 22 | catfile: Option, 23 | 24 | #[structopt(short = "d", long = "dead")] 25 | /// Make the cat appears dead 26 | dead: bool, 27 | } 28 | 29 | fn main() -> Result<(), ExitFailure> { 30 | let options = Options::from_args(); 31 | let mut message = String::new(); 32 | if options.stdin { 33 | io::stdin().read_to_string(&mut message)?; 34 | } else { 35 | message = options.message; 36 | }; 37 | 38 | let stdout = io::stdout(); 39 | let mut handle = io::BufWriter::new(stdout); 40 | 41 | if message.to_lowercase() == "woof" { 42 | eprintln!("A cat shouldn't bark like a dog.") 43 | } 44 | 45 | let eye = if options.dead { "x" } else { "o" }; 46 | 47 | let cat_template = match &options.catfile { 48 | Some(path) => std::fs::read_to_string(path) 49 | .with_context(|_| format!("could not read file {:?}", path))?, 50 | None => String::from( 51 | " 52 | \\ 53 | \\ 54 | /\\_/\\ 55 | ( {eye} {eye} ) 56 | =( I )=", 57 | ), 58 | }; 59 | 60 | let cat_picture = cat_template.replace("{eye}", eye); 61 | writeln!( 62 | handle, 63 | "{}", 64 | message.bright_yellow().underline().on_purple() 65 | )?; 66 | writeln!(handle, "{}", &cat_picture)?; 67 | Ok(()) 68 | } 69 | -------------------------------------------------------------------------------- /cli/catsay/tests/integration_test.rs: -------------------------------------------------------------------------------- 1 | use assert_cmd::prelude::*; // Add methods on commands 2 | use predicates::prelude::*; 3 | use std::process::Command; // Run programs // Used for writing assertions 4 | 5 | #[test] 6 | fn run_with_defaults() -> Result<(), Box> { 7 | Command::cargo_bin("catsay") 8 | .expect("binary exists") 9 | .assert() 10 | .success() 11 | .stdout(predicate::str::contains("Meow!")); 12 | Ok(()) 13 | } 14 | 15 | #[test] 16 | fn fail_on_non_existing_file() -> Result<(), Box> { 17 | Command::cargo_bin("catsay") 18 | .expect("binary exists") 19 | .args(&["-f", "no/such/file.txt"]) 20 | .assert() 21 | .failure(); 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /errata.md: -------------------------------------------------------------------------------- 1 | # Errata for *Book Title* 2 | 3 | On **page xx** [Summary of error]: 4 | 5 | Details of error here. Highlight key pieces in **bold**. 6 | 7 | *** 8 | 9 | On **page xx** [Summary of error]: 10 | 11 | Details of error here. Highlight key pieces in **bold**. 12 | 13 | *** -------------------------------------------------------------------------------- /game/cat_volleyball/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | ../ 3 | -------------------------------------------------------------------------------- /game/cat_volleyball/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cat_volleyball" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu"] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | amethyst = { version = "0.13.2", features = ["vulkan"] } 9 | rand = "0.6.5" 10 | -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/Computer_Music_All-Stars_-_Albatross_v2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/Computer_Music_All-Stars_-_Albatross_v2.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/LICENSE_AUDIO.txt: -------------------------------------------------------------------------------- 1 | # Licenses for audio assets 2 | 3 | - `boop.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 4 | - `confirm.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 5 | - `bounce.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 6 | - `score.ogg`: Contributed by Richard Dodd, released into the Public Domain (CC0) 7 | - `Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg` (BY) 8 | - `Computer_Music_All-Starts_-_Albatross_v2.ogg` (BY) 9 | -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/boop.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/boop.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/bounce.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/bounce.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/confirm.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/confirm.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/audio/score.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/audio/score.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/assets/font/square.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/font/square.ttf -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/texture/ball.png -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/ball_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/texture/ball_color.png -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/pixel-cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/texture/pixel-cat.png -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/pixel-cat_flipped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/texture/pixel-cat_flipped.png -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/spritesheet.json: -------------------------------------------------------------------------------- 1 | { 2 | "frames": { 3 | "ball_color.png": { 4 | "frame": { 5 | "x": 1, 6 | "y": 1, 7 | "w": 8, 8 | "h": 8 9 | }, 10 | "rotated": false, 11 | "trimmed": false, 12 | "spriteSourceSize": { 13 | "x": 0, 14 | "y": 0, 15 | "w": 8, 16 | "h": 8 17 | }, 18 | "sourceSize": { 19 | "w": 8, 20 | "h": 8 21 | } 22 | }, 23 | "pixel-cat.png": { 24 | "frame": { 25 | "x": 11, 26 | "y": 1, 27 | "w": 22, 28 | "h": 32 29 | }, 30 | "rotated": false, 31 | "trimmed": false, 32 | "spriteSourceSize": { 33 | "x": 0, 34 | "y": 0, 35 | "w": 22, 36 | "h": 32 37 | }, 38 | "sourceSize": { 39 | "w": 22, 40 | "h": 32 41 | } 42 | } 43 | }, 44 | "meta": { 45 | "app": "http://www.codeandweb.com/texturepacker", 46 | "version": "1.0", 47 | "image": "spritesheet.png", 48 | "format": "RGBA8888", 49 | "size": { 50 | "w": 34, 51 | "h": 34 52 | }, 53 | "scale": "1" 54 | } 55 | } -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/spritesheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/assets/texture/spritesheet.png -------------------------------------------------------------------------------- /game/cat_volleyball/assets/texture/spritesheet.ron: -------------------------------------------------------------------------------- 1 | ( 2 | texture_width: 58, 3 | texture_height: 34, 4 | sprites: [ 5 | ( 6 | x: 11, 7 | y: 1, 8 | width: 22, 9 | height: 32, 10 | ), 11 | ( 12 | x: 35, 13 | y: 1, 14 | width: 22, 15 | height: 32, 16 | ), 17 | ( 18 | x: 1, 19 | y: 1, 20 | width: 8, 21 | height: 8, 22 | ), 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /game/cat_volleyball/audio/Computer_Music_All-Stars_-_Albatross_v2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/audio/Computer_Music_All-Stars_-_Albatross_v2.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/audio/Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/audio/Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/audio/LICENSE_AUDIO.txt: -------------------------------------------------------------------------------- 1 | # Licenses for audio assets 2 | 3 | - `boop.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 4 | - `confirm.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 5 | - `bounce.ogg`: Contributed by Jacob Kiesel, released into the Public Domain (CC0) 6 | - `score.ogg`: Contributed by Richard Dodd, released into the Public Domain (CC0) 7 | - `Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg` (BY) 8 | - `Computer_Music_All-Starts_-_Albatross_v2.ogg` (BY) 9 | -------------------------------------------------------------------------------- /game/cat_volleyball/audio/bounce.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/audio/bounce.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/audio/score.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/audio/score.ogg -------------------------------------------------------------------------------- /game/cat_volleyball/font/square.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/font/square.ttf -------------------------------------------------------------------------------- /game/cat_volleyball/resources/bindings_config.ron: -------------------------------------------------------------------------------- 1 | ( 2 | axes: { 3 | "left_player": Emulated(pos: Key(D), neg: Key(A)), 4 | "right_player": Emulated(pos: Key(Right), neg: Key(Left)), 5 | }, 6 | actions: {}, 7 | ) 8 | -------------------------------------------------------------------------------- /game/cat_volleyball/resources/display_config.ron: -------------------------------------------------------------------------------- 1 | ( 2 | title: "cat_volleyball", 3 | dimensions: Some((500, 500)), 4 | max_dimensions: None, 5 | min_dimensions: None, 6 | fullscreen: None, 7 | multisampling: 1, 8 | visibility: true, 9 | vsync: true, 10 | ) 11 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/audio.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | assets::{AssetStorage, Loader}, 3 | audio::{output::Output, AudioSink, OggFormat, Source, SourceHandle}, 4 | ecs::{World, WorldExt}, 5 | }; 6 | use std::iter::Cycle; 7 | use std::vec::IntoIter; 8 | 9 | pub struct Sounds { 10 | pub score_sfx: SourceHandle, 11 | pub bounce_sfx: SourceHandle, 12 | } 13 | 14 | pub struct Music { 15 | pub music: Cycle>, 16 | } 17 | 18 | /// Loads an ogg audio track. 19 | fn load_audio_track(loader: &Loader, world: &World, file: &str) -> SourceHandle { 20 | println!("{}", file); 21 | loader.load(file, OggFormat, (), &world.read_resource()) 22 | } 23 | 24 | /// Initialise audio in the world. This includes the background track and the 25 | /// sound effects. 26 | pub fn initialise_audio(world: &mut World) { 27 | use crate::catvolleyball::{AUDIO_BOUNCE, AUDIO_MUSIC, AUDIO_SCORE}; 28 | println!("init music"); 29 | 30 | let (sound_effects, music) = { 31 | let loader = world.read_resource::(); 32 | 33 | let mut sink = world.write_resource::(); 34 | sink.set_volume(0.25); // Music is a bit loud, reduce the volume. 35 | 36 | println!("Loading music"); 37 | let music = AUDIO_MUSIC 38 | .iter() 39 | .map(|file| load_audio_track(&loader, &world, file)) 40 | .collect::>() 41 | .into_iter() 42 | .cycle(); 43 | let music = Music { music }; 44 | 45 | let sound = Sounds { 46 | bounce_sfx: load_audio_track(&loader, &world, AUDIO_BOUNCE), 47 | score_sfx: load_audio_track(&loader, &world, AUDIO_SCORE), 48 | }; 49 | 50 | (sound, music) 51 | }; 52 | 53 | // Add sound effects to the world. We have to do this in another scope because 54 | // world won't let us insert new resources as long as `Loader` is borrowed. 55 | world.insert(sound_effects); 56 | world.insert(music); 57 | } 58 | 59 | /// Plays the bounce sound when a ball hits a side or a paddle. 60 | pub fn play_bounce(sounds: &Sounds, storage: &AssetStorage, output: Option<&Output>) { 61 | if let Some(ref output) = output.as_ref() { 62 | if let Some(sound) = storage.get(&sounds.bounce_sfx) { 63 | output.play_once(sound, 1.0); 64 | } 65 | } 66 | } 67 | 68 | /// Plays the score sound when a player scores 69 | pub fn play_score(sounds: &Sounds, storage: &AssetStorage, output: Option<&Output>) { 70 | if let Some(ref output) = output.as_ref() { 71 | if let Some(sound) = storage.get(&sounds.score_sfx) { 72 | output.play_once(sound, 1.0); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/catvolleyball.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | assets::{AssetStorage, Handle, Loader}, 3 | core::transform::Transform, 4 | ecs::prelude::{Component, DenseVecStorage, Entity}, 5 | prelude::*, 6 | renderer::{Camera, ImageFormat, SpriteRender, SpriteSheet, SpriteSheetFormat, Texture}, 7 | ui::{Anchor, TtfFormat, UiText, UiTransform}, 8 | }; 9 | 10 | use crate::audio::initialise_audio; 11 | 12 | pub const ARENA_HEIGHT: f32 = 200.0; 13 | pub const ARENA_WIDTH: f32 = 200.0; 14 | 15 | pub const PLAYER_HEIGHT: f32 = 32.0; 16 | pub const PLAYER_WIDTH: f32 = 22.0; 17 | 18 | pub const BALL_VELOCITY_X: f32 = 30.0; 19 | pub const BALL_VELOCITY_Y: f32 = 0.0; 20 | pub const BALL_RADIUS: f32 = 4.0; 21 | 22 | pub const AUDIO_MUSIC: &'static [&'static str] = &[ 23 | "./audio/Computer_Music_All-Stars_-_Wheres_My_Jetpack.ogg", 24 | "./audio/Computer_Music_All-Stars_-_Albatross_v2.ogg", 25 | ]; 26 | pub const AUDIO_BOUNCE: &'static str = "./audio/bounce.ogg"; 27 | pub const AUDIO_SCORE: &'static str = "./audio/score.ogg"; 28 | 29 | // Player 30 | #[derive(PartialEq, Eq)] 31 | pub enum Side { 32 | Left, 33 | Right, 34 | } 35 | 36 | pub struct Player { 37 | pub side: Side, 38 | pub width: f32, 39 | pub height: f32, 40 | } 41 | 42 | impl Player { 43 | fn new(side: Side) -> Player { 44 | Player { 45 | side, 46 | width: PLAYER_WIDTH, 47 | height: PLAYER_HEIGHT, 48 | } 49 | } 50 | } 51 | 52 | impl Component for Player { 53 | type Storage = DenseVecStorage; 54 | } 55 | 56 | // Ball 57 | pub struct Ball { 58 | pub velocity: [f32; 2], 59 | pub radius: f32, 60 | } 61 | 62 | impl Component for Ball { 63 | type Storage = DenseVecStorage; 64 | } 65 | 66 | /// Initialises one ball in the middle-ish of the arena. 67 | fn initialise_ball(world: &mut World, sprite_sheet_handle: Handle) { 68 | // Create the translation. 69 | let mut local_transform = Transform::default(); 70 | local_transform.set_translation_xyz(ARENA_WIDTH / 2.0, ARENA_HEIGHT / 2.0, 0.0); 71 | 72 | // Assign the sprite for the ball 73 | let sprite_render = SpriteRender { 74 | sprite_sheet: sprite_sheet_handle, 75 | sprite_number: 2, // ball is the third sprite on the sprite sheet 76 | }; 77 | 78 | world 79 | .create_entity() 80 | .with(sprite_render) 81 | .with(Ball { 82 | radius: BALL_RADIUS, 83 | velocity: [BALL_VELOCITY_X, BALL_VELOCITY_Y], 84 | }) 85 | .with(local_transform) 86 | .build(); 87 | } 88 | 89 | fn initialise_camera(world: &mut World) { 90 | let mut transform = Transform::default(); 91 | transform.set_translation_xyz(ARENA_WIDTH * 0.5, ARENA_HEIGHT * 0.5, 1.0); 92 | world 93 | .create_entity() 94 | .with(Camera::standard_2d(ARENA_WIDTH, ARENA_HEIGHT)) 95 | .with(transform) 96 | .build(); 97 | } 98 | 99 | fn load_sprite_sheet(world: &mut World) -> Handle { 100 | // Load the sprite sheet necessary to render the graphics. 101 | // The texture is the pixel data 102 | // `texture_handle` is a cloneable reference to the texture 103 | let texture_handle = { 104 | let loader = world.read_resource::(); 105 | let texture_storage = world.read_resource::>(); 106 | loader.load( 107 | "texture/spritesheet.png", 108 | ImageFormat::default(), 109 | (), 110 | &texture_storage, 111 | ) 112 | }; 113 | let loader = world.read_resource::(); 114 | let sprite_sheet_store = world.read_resource::>(); 115 | loader.load( 116 | "texture/spritesheet.ron", 117 | SpriteSheetFormat(texture_handle), 118 | (), 119 | &sprite_sheet_store, 120 | ) 121 | } 122 | 123 | /// Initialises one player on each side of the arena 124 | fn initialise_players(world: &mut World, sprite_sheet: Handle) { 125 | let mut left_transform = Transform::default(); 126 | let mut right_transform = Transform::default(); 127 | 128 | let y = PLAYER_HEIGHT / 2.0; 129 | left_transform.set_translation_xyz(PLAYER_WIDTH * 0.5, y, 0.0); 130 | right_transform.set_translation_xyz(ARENA_WIDTH - PLAYER_WIDTH * 0.5, y, 0.0); 131 | 132 | let sprite_render_left = SpriteRender { 133 | sprite_sheet: sprite_sheet.clone(), 134 | sprite_number: 0, // paddle is the first sprite in the sprite_sheet 135 | }; 136 | 137 | let sprite_render_right = SpriteRender { 138 | sprite_sheet: sprite_sheet.clone(), 139 | sprite_number: 1, // paddle is the first sprite in the sprite_sheet 140 | }; 141 | 142 | // Create a left plank entity. 143 | world 144 | .create_entity() 145 | .with(sprite_render_left.clone()) 146 | .with(Player::new(Side::Left)) 147 | .with(left_transform) 148 | .build(); 149 | 150 | // Create right plank entity. 151 | world 152 | .create_entity() 153 | .with(sprite_render_right.clone()) 154 | .with(Player::new(Side::Right)) 155 | .with(right_transform) 156 | .build(); 157 | } 158 | 159 | // UI 160 | /// ScoreBoard contains the actual score data 161 | #[derive(Default)] 162 | pub struct ScoreBoard { 163 | pub score_left: i32, 164 | pub score_right: i32, 165 | } 166 | 167 | /// ScoreText contains the ui text elements that display the score 168 | pub struct ScoreText { 169 | pub p1_score: Entity, 170 | pub p2_score: Entity, 171 | } 172 | 173 | /// Initialises a ui scoreboard 174 | fn initialise_scoreboard(world: &mut World) { 175 | let font = world.read_resource::().load( 176 | "font/square.ttf", 177 | TtfFormat, 178 | (), 179 | &world.read_resource(), 180 | ); 181 | 182 | let p1_transform = UiTransform::new( 183 | "P1".to_string(), // ID 184 | Anchor::TopMiddle, // anchor 185 | Anchor::Middle, // pivot 186 | -50., // x 187 | -50., // y 188 | 1., // z 189 | 200., // width 190 | 50., // height 191 | ); 192 | let p2_transform = UiTransform::new( 193 | "P2".to_string(), 194 | Anchor::TopMiddle, 195 | Anchor::Middle, 196 | 50., 197 | -50., 198 | 1., 199 | 200., 200 | 50., 201 | ); 202 | 203 | let p1_score = world 204 | .create_entity() 205 | .with(p1_transform) 206 | .with(UiText::new( 207 | font.clone(), 208 | "0".to_string(), 209 | [1., 1., 1., 1.], 210 | 50., 211 | )) 212 | .build(); 213 | 214 | let p2_score = world 215 | .create_entity() 216 | .with(p2_transform) 217 | .with(UiText::new( 218 | font.clone(), 219 | "0".to_string(), 220 | [1., 1., 1., 1.], 221 | 50., 222 | )) 223 | .build(); 224 | 225 | world.insert(ScoreText { p1_score, p2_score }); 226 | } 227 | 228 | pub struct CatVolleyball; 229 | 230 | impl SimpleState for CatVolleyball { 231 | fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { 232 | let world = data.world; 233 | let sprite_sheet_handle = load_sprite_sheet(world); 234 | 235 | //world.register::(); // We need this because we haven't have any System yet. Otherwise the components used by the System will be registered by default 236 | world.register::(); 237 | 238 | initialise_ball(world, sprite_sheet_handle.clone()); 239 | initialise_players(world, sprite_sheet_handle); 240 | initialise_camera(world); 241 | initialise_scoreboard(world); 242 | initialise_audio(world); 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/main.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | audio::{AudioBundle, DjSystemDesc}, 3 | core::transform::TransformBundle, 4 | input::{InputBundle, StringBindings}, 5 | prelude::*, 6 | renderer::{ 7 | plugins::{RenderFlat2D, RenderToWindow}, 8 | types::DefaultBackend, 9 | RenderingBundle, 10 | }, 11 | ui::{RenderUi, UiBundle}, 12 | utils::application_root_dir, 13 | }; 14 | 15 | mod audio; 16 | mod catvolleyball; 17 | mod systems; 18 | 19 | use crate::audio::Music; 20 | use crate::catvolleyball::CatVolleyball; 21 | 22 | fn main() -> amethyst::Result<()> { 23 | amethyst::start_logger(Default::default()); 24 | 25 | let app_root = application_root_dir().unwrap(); 26 | let display_config_path = app_root.join("resources").join("display_config.ron"); 27 | 28 | let binding_path = app_root.join("resources").join("bindings_config.ron"); 29 | let input_bundle = 30 | InputBundle::::new().with_bindings_from_file(binding_path)?; 31 | 32 | let game_data = GameDataBuilder::default() 33 | .with_bundle(TransformBundle::new())? 34 | .with_bundle(UiBundle::::new())? 35 | .with_bundle(input_bundle)? 36 | .with_bundle(AudioBundle::default())? 37 | .with_system_desc( 38 | DjSystemDesc::new(|music: &mut Music| music.music.next()), 39 | "dj_system", 40 | &[], 41 | ) 42 | .with(systems::PlayerSystem, "player_system", &["input_system"]) 43 | // ^ the system ^ its name ^ dependencies 44 | // The renderer must be executed on the same thread consecutively, so we initialize it as thread_local 45 | // which will always execute on the main thread. 46 | .with(systems::MoveBallsSystem, "ball_system", &[]) 47 | .with( 48 | systems::BounceSystem, 49 | "collision_system", 50 | &["player_system", "ball_system"], 51 | ) 52 | .with(systems::WinnerSystem, "winner_system", &["ball_system"]) 53 | .with_bundle( 54 | RenderingBundle::::new() 55 | .with_plugin( 56 | RenderToWindow::from_config_path(display_config_path) 57 | .with_clear([0.0, 0.0, 0.0, 1.0]), 58 | ) 59 | .with_plugin(RenderFlat2D::default()) 60 | .with_plugin(RenderUi::default()), 61 | )?; 62 | 63 | let assets_dir = app_root.join("assets"); 64 | let mut game = Application::new(assets_dir, CatVolleyball, game_data)?; 65 | game.run(); 66 | 67 | Ok(()) 68 | } 69 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/systems/bounce.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | assets::AssetStorage, 3 | audio::{output::Output, Source}, 4 | core::transform::Transform, 5 | core::SystemDesc, 6 | derive::SystemDesc, 7 | ecs::prelude::{Join, Read, ReadExpect, ReadStorage, System, SystemData, World, WriteStorage}, 8 | }; 9 | 10 | extern crate rand; 11 | use rand::Rng; 12 | use std::ops::Deref; 13 | 14 | use crate::audio::{play_bounce, Sounds}; 15 | use crate::catvolleyball::{Ball, Player, Side, ARENA_HEIGHT, ARENA_WIDTH}; 16 | 17 | #[derive(SystemDesc)] 18 | pub struct BounceSystem; 19 | 20 | impl<'s> System<'s> for BounceSystem { 21 | type SystemData = ( 22 | WriteStorage<'s, Ball>, 23 | ReadStorage<'s, Player>, 24 | ReadStorage<'s, Transform>, 25 | Read<'s, AssetStorage>, 26 | ReadExpect<'s, Sounds>, 27 | Option>, 28 | ); 29 | 30 | fn run( 31 | &mut self, 32 | (mut balls, players, transforms, storage, sounds, audio_output): Self::SystemData, 33 | ) { 34 | // Check whether a ball collided, and bounce off accordingly. 35 | // 36 | // We also check for the velocity of the ball every time, to prevent multiple collisions 37 | // from occurring. 38 | for (ball, transform) in (&mut balls, &transforms).join() { 39 | let ball_x = transform.translation().x; 40 | let ball_y = transform.translation().y; 41 | 42 | // Bounce at the four sides of the arena. 43 | if ball_y <= ball.radius && ball.velocity[1] < 0.0 { 44 | ball.velocity[1] = -ball.velocity[1]; 45 | // Don't play the sound since we are going to play the score sound 46 | } else if ball_y >= (ARENA_HEIGHT - ball.radius) && ball.velocity[1] > 0.0 { 47 | ball.velocity[1] = -ball.velocity[1]; 48 | play_bounce(&*sounds, &storage, audio_output.as_ref().map(|o| o.deref())); 49 | } else if ball_x <= ball.radius && ball.velocity[0] < 0.0 { 50 | ball.velocity[0] = -ball.velocity[0]; 51 | play_bounce(&*sounds, &storage, audio_output.as_ref().map(|o| o.deref())); 52 | } else if ball_x >= (ARENA_WIDTH - ball.radius) && ball.velocity[0] > 0.0 { 53 | ball.velocity[0] = -ball.velocity[0]; 54 | play_bounce(&*sounds, &storage, audio_output.as_ref().map(|o| o.deref())); 55 | } 56 | 57 | // Bounce at the players. 58 | for (player, player_transform) in (&players, &transforms).join() { 59 | let player_x = player_transform.translation().x - (player.width * 0.5); 60 | let player_y = player_transform.translation().y - (player.height * 0.5); 61 | 62 | // To determine whether the ball has collided with a player, we create a larger 63 | // rectangle around the current one, by subtracting the ball radius from the 64 | // lowest coordinates, and adding the ball radius to the highest ones. The ball 65 | // is then within the player if its centre is within the larger wrapper 66 | // rectangle. 67 | if point_in_rect( 68 | ball_x, 69 | ball_y, 70 | player_x - ball.radius, 71 | player_y - ball.radius, 72 | player_x + player.width + ball.radius, 73 | player_y + player.height + ball.radius, 74 | ) { 75 | if ball.velocity[1] < 0.0 { 76 | // Only bounce when ball is falling 77 | ball.velocity[1] = -ball.velocity[1]; 78 | 79 | let mut rng = rand::thread_rng(); 80 | match player.side { 81 | Side::Left => { 82 | ball.velocity[0] = ball.velocity[0].abs() * rng.gen_range(0.6, 1.4) 83 | } 84 | Side::Right => { 85 | ball.velocity[0] = -ball.velocity[0].abs() * rng.gen_range(0.6, 1.4) 86 | } 87 | } 88 | play_bounce(&*sounds, &storage, audio_output.as_ref().map(|o| o.deref())); 89 | } 90 | } 91 | } 92 | } 93 | } 94 | } 95 | 96 | // A point is in a box when its coordinates are smaller or equal than the top 97 | // right and larger or equal than the bottom left. 98 | fn point_in_rect(x: f32, y: f32, left: f32, bottom: f32, right: f32, top: f32) -> bool { 99 | x >= left && x <= right && y >= bottom && y <= top 100 | } 101 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/systems/mod.rs: -------------------------------------------------------------------------------- 1 | mod bounce; 2 | mod move_balls; 3 | mod player; 4 | mod winner; 5 | 6 | pub use self::bounce::BounceSystem; 7 | pub use self::move_balls::MoveBallsSystem; 8 | pub use self::player::PlayerSystem; 9 | pub use self::winner::WinnerSystem; 10 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/systems/move_balls.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | core::timing::Time, 3 | core::transform::Transform, 4 | core::SystemDesc, 5 | derive::SystemDesc, 6 | ecs::prelude::{Join, Read, System, SystemData, World, WriteStorage}, 7 | }; 8 | 9 | use crate::catvolleyball::Ball; 10 | 11 | #[derive(SystemDesc)] 12 | pub struct MoveBallsSystem; 13 | 14 | pub const GRAVITY_ACCELERATION: f32 = -40.0; 15 | 16 | impl<'s> System<'s> for MoveBallsSystem { 17 | type SystemData = ( 18 | WriteStorage<'s, Ball>, 19 | WriteStorage<'s, Transform>, 20 | Read<'s, Time>, 21 | ); 22 | 23 | fn run(&mut self, (mut balls, mut locals, time): Self::SystemData) { 24 | // Move every ball according to its speed, and the time passed. 25 | // https://gamedev.stackexchange.com/questions/15708/how-can-i-implement-gravity 26 | for (ball, local) in (&mut balls, &mut locals).join() { 27 | local.prepend_translation_x(ball.velocity[0] * time.delta_seconds()); 28 | local.prepend_translation_y( 29 | (ball.velocity[1] + time.delta_seconds() * GRAVITY_ACCELERATION / 2.0) 30 | * time.delta_seconds(), 31 | ); 32 | ball.velocity[1] = ball.velocity[1] + time.delta_seconds() * GRAVITY_ACCELERATION; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/systems/player.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | core::timing::Time, 3 | core::SystemDesc, 4 | core::Transform, 5 | derive::SystemDesc, 6 | ecs::{Join, Read, ReadStorage, System, SystemData, World, WriteStorage}, 7 | input::{InputHandler, StringBindings}, 8 | }; 9 | 10 | use crate::catvolleyball::{Player, Side, ARENA_WIDTH, PLAYER_WIDTH}; 11 | 12 | const PLAYER_SPEED: f32 = 60.0; 13 | 14 | #[derive(SystemDesc)] 15 | pub struct PlayerSystem; 16 | 17 | impl<'s> System<'s> for PlayerSystem { 18 | type SystemData = ( 19 | WriteStorage<'s, Transform>, 20 | ReadStorage<'s, Player>, 21 | Read<'s, Time>, 22 | Read<'s, InputHandler>, 23 | ); 24 | 25 | fn run(&mut self, (mut transforms, players, time, input): Self::SystemData) { 26 | for (player, transform) in (&players, &mut transforms).join() { 27 | let movement = match player.side { 28 | Side::Left => input.axis_value("left_player"), 29 | Side::Right => input.axis_value("right_player"), 30 | }; 31 | if let Some(mv_amount) = movement { 32 | let scaled_amount = PLAYER_SPEED * time.delta_seconds() * mv_amount as f32; 33 | let player_x = transform.translation().x; 34 | let player_left_limit = match player.side { 35 | Side::Left => 0.0, 36 | Side::Right => ARENA_WIDTH / 2.0, 37 | }; 38 | transform.set_translation_x( 39 | (player_x + scaled_amount) 40 | .max(player_left_limit + PLAYER_WIDTH / 2.0) 41 | .min(player_left_limit + ARENA_WIDTH / 2.0 - PLAYER_WIDTH / 2.0), 42 | ); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /game/cat_volleyball/src/systems/winner.rs: -------------------------------------------------------------------------------- 1 | use amethyst::{ 2 | assets::AssetStorage, 3 | audio::{output::Output, Source}, 4 | core::transform::Transform, 5 | core::SystemDesc, 6 | derive::SystemDesc, 7 | ecs::prelude::{Join, Read, ReadExpect, System, SystemData, World, Write, WriteStorage}, 8 | ui::UiText, 9 | }; 10 | 11 | use crate::audio::{play_score, Sounds}; 12 | use crate::catvolleyball::{Ball, ScoreBoard, ScoreText, ARENA_HEIGHT, ARENA_WIDTH}; 13 | use std::ops::Deref; 14 | 15 | #[derive(SystemDesc)] 16 | pub struct WinnerSystem; 17 | 18 | impl<'s> System<'s> for WinnerSystem { 19 | type SystemData = ( 20 | WriteStorage<'s, Ball>, 21 | WriteStorage<'s, Transform>, 22 | WriteStorage<'s, UiText>, 23 | Write<'s, ScoreBoard>, 24 | ReadExpect<'s, ScoreText>, 25 | Read<'s, AssetStorage>, 26 | ReadExpect<'s, Sounds>, 27 | Option>, 28 | ); 29 | 30 | fn run( 31 | &mut self, 32 | (mut balls, mut locals, mut ui_text, mut scores, score_text, storage, sounds, audio_output): Self::SystemData, 33 | ) { 34 | for (ball, transform) in (&mut balls, &mut locals).join() { 35 | let ball_x = transform.translation().x; 36 | let ball_y = transform.translation().y; 37 | 38 | if ball_y <= ball.radius { 39 | // touched the ground 40 | if ball_x <= ARENA_WIDTH / 2.0 { 41 | println!("Right player scored"); 42 | scores.score_right = (scores.score_right + 1).min(999); 43 | 44 | if let Some(text) = ui_text.get_mut(score_text.p2_score) { 45 | text.text = scores.score_right.to_string(); 46 | } 47 | } else { 48 | scores.score_left = (scores.score_left + 1).min(999); 49 | if let Some(text) = ui_text.get_mut(score_text.p1_score) { 50 | text.text = scores.score_left.to_string(); 51 | } 52 | } 53 | 54 | // reset the ball to the middle 55 | transform.set_translation_x(ARENA_WIDTH / 2.0); 56 | transform.set_translation_y(ARENA_HEIGHT / 2.0); 57 | ball.velocity[0] = -ball.velocity[0]; // reverse the direction 58 | ball.velocity[1] = 0.0; // reset to free drop 59 | 60 | // Play audio. 61 | play_score(&*sounds, &storage, audio_output.as_ref().map(|o| o.deref())); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /game/cat_volleyball/texture/spritesheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/game/cat_volleyball/texture/spritesheet.png -------------------------------------------------------------------------------- /game/cat_volleyball/texture/spritesheet.ron: -------------------------------------------------------------------------------- 1 | ( 2 | spritesheet_width: 58, 3 | spritesheet_height: 34, 4 | sprites: [ 5 | ( 6 | x: 11, 7 | y: 1, 8 | width: 22, 9 | height: 32, 10 | ), 11 | ( 12 | x: 35, 13 | y: 1, 14 | width: 22, 15 | height: 32, 16 | ), 17 | ( 18 | x: 1, 19 | y: 1, 20 | width: 8, 21 | height: 8, 22 | ), 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "atk" 5 | version = "0.6.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 9 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 10 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 11 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 12 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 13 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 14 | ] 15 | 16 | [[package]] 17 | name = "atk-sys" 18 | version = "0.8.0" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | dependencies = [ 21 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 22 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 23 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 24 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 25 | ] 26 | 27 | [[package]] 28 | name = "bitflags" 29 | version = "1.0.5" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | 32 | [[package]] 33 | name = "cairo-rs" 34 | version = "0.6.0" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | dependencies = [ 37 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 38 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 39 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 40 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 41 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 42 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 43 | ] 44 | 45 | [[package]] 46 | name = "cairo-sys-rs" 47 | version = "0.8.0" 48 | source = "registry+https://github.com/rust-lang/crates.io-index" 49 | dependencies = [ 50 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 51 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 53 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 54 | ] 55 | 56 | [[package]] 57 | name = "catsay-gui-glade" 58 | version = "0.1.0" 59 | dependencies = [ 60 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 61 | "gtk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 62 | ] 63 | 64 | [[package]] 65 | name = "cc" 66 | version = "1.0.36" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | 69 | [[package]] 70 | name = "fragile" 71 | version = "0.3.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "gdk" 76 | version = "0.10.0" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | dependencies = [ 79 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 82 | "gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 91 | ] 92 | 93 | [[package]] 94 | name = "gdk-pixbuf" 95 | version = "0.6.0" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | dependencies = [ 98 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 100 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 103 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 104 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 105 | ] 106 | 107 | [[package]] 108 | name = "gdk-pixbuf-sys" 109 | version = "0.8.0" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | dependencies = [ 112 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 113 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 114 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 115 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 116 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 117 | ] 118 | 119 | [[package]] 120 | name = "gdk-sys" 121 | version = "0.8.0" 122 | source = "registry+https://github.com/rust-lang/crates.io-index" 123 | dependencies = [ 124 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 125 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 126 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 129 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 130 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 131 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 132 | ] 133 | 134 | [[package]] 135 | name = "gio" 136 | version = "0.6.0" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | dependencies = [ 139 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 140 | "fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 141 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 142 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 143 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 144 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 145 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 146 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 147 | ] 148 | 149 | [[package]] 150 | name = "gio-sys" 151 | version = "0.8.0" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | dependencies = [ 154 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 155 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 156 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 157 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 158 | ] 159 | 160 | [[package]] 161 | name = "glib" 162 | version = "0.7.1" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | dependencies = [ 165 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 166 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 167 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 168 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 169 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 170 | ] 171 | 172 | [[package]] 173 | name = "glib-sys" 174 | version = "0.8.0" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | dependencies = [ 177 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 178 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 179 | ] 180 | 181 | [[package]] 182 | name = "gobject-sys" 183 | version = "0.8.0" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | dependencies = [ 186 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 189 | ] 190 | 191 | [[package]] 192 | name = "gtk" 193 | version = "0.6.0" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | dependencies = [ 196 | "atk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 197 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 198 | "cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 199 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 200 | "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", 201 | "gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 202 | "gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 203 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 204 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 205 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 206 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 207 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 208 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 209 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 210 | "gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 211 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 212 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 213 | "pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 215 | ] 216 | 217 | [[package]] 218 | name = "gtk-sys" 219 | version = "0.8.0" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | dependencies = [ 222 | "atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 223 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 224 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 225 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 226 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 227 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 228 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 229 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 230 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 231 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 232 | ] 233 | 234 | [[package]] 235 | name = "lazy_static" 236 | version = "1.3.0" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | 239 | [[package]] 240 | name = "libc" 241 | version = "0.2.54" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | 244 | [[package]] 245 | name = "pango" 246 | version = "0.6.0" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | dependencies = [ 249 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 254 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 255 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 256 | ] 257 | 258 | [[package]] 259 | name = "pango-sys" 260 | version = "0.8.0" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | dependencies = [ 263 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 265 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 266 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 267 | ] 268 | 269 | [[package]] 270 | name = "pkg-config" 271 | version = "0.3.14" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | 274 | [[package]] 275 | name = "winapi" 276 | version = "0.3.7" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | dependencies = [ 279 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 280 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 281 | ] 282 | 283 | [[package]] 284 | name = "winapi-i686-pc-windows-gnu" 285 | version = "0.4.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | 288 | [[package]] 289 | name = "winapi-x86_64-pc-windows-gnu" 290 | version = "0.4.0" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | 293 | [metadata] 294 | "checksum atk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ce8fd2055aa2ce617754c5a701682a06b4b57093cbbcbd8f068622a8debae96" 295 | "checksum atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83744274abbcc2242f845a25cf84b9adb5991eaecc8f7c67cffd69ea636f4ff8" 296 | "checksum bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bd1fa8ad26490b0a5cfec99089952250301b6716cdeaa7c9ab229598fb82ab66" 297 | "checksum cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e09d8a818b2ccc8983f04d95a9350c3cf8d24cc456cedca3b88fa3a81fdc0e2" 298 | "checksum cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fa13914fdc013387afa771f554f2f71d6ae931f4e5be9246c337d60c3dc484" 299 | "checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d" 300 | "checksum fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9" 301 | "checksum gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c229b642a3cf701f92246b131fda2eaabaa5f44f4a255dee65939ebd0ab0141" 302 | "checksum gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a1bcb11b461ff5638f6bf03c9f173d3dc250eabc8e57a60644b6f529d3a7c91" 303 | "checksum gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10e1115ca451907b6d775fc0392641d14c89277662d98828412fb68555e7e8c8" 304 | "checksum gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "458dc6243bdda4aa1693f5f18231f55b98e9c99c50b3b9bd673cf461ef1710ea" 305 | "checksum gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff120a666f4a0f41cca7554fbac82defc2562e90eccf3b26a30e6461fa1bbde8" 306 | "checksum gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04957c40df00dd72f7c9ec8e382b01ff8ed4a904fcd2fa608b7ae7fbaccfda8f" 307 | "checksum glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e8fdc159c196a5dfa53a92929ac4c10c8a6637ffb43951f3fff89c2cd2365" 308 | "checksum glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bda542f3caee39a027638e9644ff89204101ad916fd7370b585ad2c5fc97e61" 309 | "checksum gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23e05a14290d3dc255223cba51db4b0f3da438d5250657996fa99b2a30faf43e" 310 | "checksum gtk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b52cfbd8c3e4a000c8374676352f3850c2d62c0f42ef0a993e5d3fcf47e0be64" 311 | "checksum gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "849835f05d46f605b00ee9fefb6d5921238c570af406f35ee7426ed01cd6795c" 312 | "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 313 | "checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" 314 | "checksum pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e36b55d7cd522bd183efeb3dfabc547bda1f26eadf8a1241dac09ab3fd3242c" 315 | "checksum pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "747ab9cd4d537e6dc5ef0e4308c10dde8b706673b0237fed4e056b8d2c0b23c8" 316 | "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" 317 | "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" 318 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 319 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 320 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "catsay-gui-glade" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | gio = "0.6.0" 9 | 10 | [dependencies.gtk] 11 | version = "0.6.0" # the gtk crate version 12 | features = ["v3_18"] # system gtk version 13 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/images/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/gui/catsay-gui-glade/images/cat.png -------------------------------------------------------------------------------- /gui/catsay-gui-glade/images/cat_dead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/gui/catsay-gui-glade/images/cat_dead.png -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/#layout.glade#: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | False 7 | Catsay 8 | 9 | 10 | True 11 | False 12 | vertical 13 | 14 | 15 | True 16 | False 17 | vertical 18 | 19 | 20 | True 21 | False 22 | immediate 23 | True 24 | 25 | 26 | True 27 | False 28 | What does the cat say: 29 | 30 | 31 | False 32 | True 33 | 0 34 | 35 | 36 | 37 | 38 | True 39 | True 40 | 41 | 42 | False 43 | True 44 | 1 45 | 46 | 47 | 48 | 49 | False 50 | True 51 | 0 52 | 53 | 54 | 55 | 56 | True 57 | False 58 | True 59 | 60 | 61 | True 62 | False 63 | Dead? 64 | 65 | 66 | False 67 | True 68 | 0 69 | 70 | 71 | 72 | 73 | True 74 | True 75 | 76 | 77 | False 78 | True 79 | 1 80 | 81 | 82 | 83 | 84 | False 85 | True 86 | 1 87 | 88 | 89 | 90 | 91 | Generate 92 | True 93 | True 94 | True 95 | 96 | 97 | False 98 | True 99 | 2 100 | 101 | 102 | 103 | 104 | False 105 | True 106 | 0 107 | 108 | 109 | 110 | 111 | True 112 | False 113 | 114 | 115 | False 116 | True 117 | 1 118 | 119 | 120 | 121 | 122 | True 123 | False 124 | vertical 125 | 126 | 127 | True 128 | False 129 | end 130 | 131 | 132 | False 133 | True 134 | 0 135 | 136 | 137 | 138 | 139 | False 140 | cat.png 141 | 142 | 143 | False 144 | True 145 | 1 146 | 147 | 148 | 149 | 150 | False 151 | True 152 | 2 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/gui/catsay-gui-glade/src/cat.png -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/layout.glade: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | False 7 | Catsay 8 | 9 | 10 | True 11 | False 12 | vertical 13 | 14 | 15 | True 16 | False 17 | vertical 18 | 19 | 20 | True 21 | False 22 | immediate 23 | True 24 | 25 | 26 | True 27 | False 28 | What does the cat say: 29 | 30 | 31 | False 32 | True 33 | 0 34 | 35 | 36 | 37 | 38 | True 39 | True 40 | 41 | 42 | False 43 | True 44 | 1 45 | 46 | 47 | 48 | 49 | False 50 | True 51 | 0 52 | 53 | 54 | 55 | 56 | True 57 | False 58 | True 59 | 60 | 61 | True 62 | False 63 | Dead? 64 | 65 | 66 | False 67 | True 68 | 0 69 | 70 | 71 | 72 | 73 | True 74 | True 75 | 76 | 77 | False 78 | True 79 | 1 80 | 81 | 82 | 83 | 84 | False 85 | True 86 | 1 87 | 88 | 89 | 90 | 91 | Generate 92 | True 93 | True 94 | True 95 | 96 | 97 | False 98 | True 99 | 2 100 | 101 | 102 | 103 | 104 | False 105 | True 106 | 0 107 | 108 | 109 | 110 | 111 | True 112 | False 113 | 114 | 115 | False 116 | True 117 | 1 118 | 119 | 120 | 121 | 122 | True 123 | False 124 | vertical 125 | 126 | 127 | True 128 | False 129 | end 130 | 131 | 132 | False 133 | True 134 | 0 135 | 136 | 137 | 138 | 139 | False 140 | cat.png 141 | 142 | 143 | False 144 | True 145 | 1 146 | 147 | 148 | 149 | 150 | False 151 | True 152 | 2 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/layout.glade~: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | False 7 | Catsay 8 | 9 | 10 | True 11 | False 12 | vertical 13 | 14 | 15 | True 16 | False 17 | vertical 18 | 19 | 20 | True 21 | False 22 | immediate 23 | True 24 | 25 | 26 | True 27 | False 28 | What does the cat say: 29 | 30 | 31 | False 32 | True 33 | 0 34 | 35 | 36 | 37 | 38 | True 39 | True 40 | 41 | 42 | False 43 | True 44 | 1 45 | 46 | 47 | 48 | 49 | False 50 | True 51 | 0 52 | 53 | 54 | 55 | 56 | True 57 | False 58 | True 59 | 60 | 61 | True 62 | False 63 | Dead? 64 | 65 | 66 | False 67 | True 68 | 0 69 | 70 | 71 | 72 | 73 | True 74 | True 75 | 76 | 77 | False 78 | True 79 | 1 80 | 81 | 82 | 83 | 84 | False 85 | True 86 | 1 87 | 88 | 89 | 90 | 91 | Generate 92 | True 93 | True 94 | True 95 | 96 | 97 | False 98 | True 99 | 2 100 | 101 | 102 | 103 | 104 | False 105 | True 106 | 0 107 | 108 | 109 | 110 | 111 | True 112 | False 113 | 114 | 115 | False 116 | True 117 | 1 118 | 119 | 120 | 121 | 122 | True 123 | False 124 | vertical 125 | 126 | 127 | True 128 | False 129 | end 130 | 131 | 132 | False 133 | True 134 | 0 135 | 136 | 137 | 138 | 139 | False 140 | ./images/cat.png 141 | 142 | 143 | False 144 | True 145 | 1 146 | 147 | 148 | 149 | 150 | False 151 | True 152 | 2 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate gio; 2 | extern crate gtk; 3 | 4 | use gio::prelude::*; 5 | use gtk::prelude::*; 6 | 7 | use std::env::args; 8 | 9 | fn build_ui(app: >k::Application) { 10 | let glade_src = include_str!("layout.glade"); 11 | let builder = gtk::Builder::new_from_string(glade_src); 12 | 13 | let window: gtk::Window = builder.get_object("applicationwindow1").unwrap(); 14 | window.set_application(app); 15 | 16 | // Inputs 17 | let message_input: gtk::Entry = builder.get_object("message_input").unwrap(); 18 | let is_dead_switch: gtk::Switch = builder.get_object("is_dead_switch").unwrap(); 19 | 20 | // Submit button 21 | let button: gtk::Button = builder.get_object("generate_btn").unwrap(); 22 | 23 | // Outputs 24 | let message_output: gtk::Label = builder.get_object("message_output").unwrap(); 25 | let image_output: gtk::Image = builder.get_object("image_output").unwrap(); 26 | let image_output_clone = image_output.clone(); 27 | 28 | button.connect_clicked(move |_| { 29 | message_output.set_text(&format!( 30 | "{}\n \\\n \\", 31 | message_input.get_text().unwrap().as_str() 32 | )); 33 | 34 | let is_dead = is_dead_switch.get_active(); 35 | if (is_dead) { 36 | image_output_clone.set_from_file("./images/cat_dead.png") 37 | } else { 38 | image_output_clone.set_from_file("./images/cat.png") 39 | } 40 | image_output_clone.show(); 41 | }); 42 | 43 | window.show_all(); 44 | image_output.hide(); 45 | } 46 | 47 | fn main() { 48 | let application = gtk::Application::new("com.shinglyu.catsay-gui-glade", Default::default()) 49 | .expect("Failed to initialize GTK"); 50 | 51 | application.connect_activate(|app| { 52 | build_ui(app); 53 | }); 54 | 55 | application.run(&args().collect::>()); 56 | } 57 | -------------------------------------------------------------------------------- /gui/catsay-gui-glade/src/main.rs.bk: -------------------------------------------------------------------------------- 1 | extern crate gio; 2 | extern crate gtk; 3 | 4 | use gio::prelude::*; 5 | use gtk::prelude::*; 6 | 7 | use std::env::args; 8 | 9 | fn build_ui(app: >k::Application) { 10 | let glade_src = include_str!("layout.glade"); 11 | let builder = gtk::Builder::new_from_string(glade_src); 12 | 13 | let window: gtk::Window = builder.get_object("applicationwindow1").unwrap(); 14 | window.set_application(app); 15 | 16 | // Inputs 17 | let message_input: gtk::Entry = builder.get_object("message_input").unwrap(); 18 | let is_dead_switch: gtk::Switch= builder.get_object("is_dead_switch").unwrap(); 19 | 20 | // Submit button 21 | let button: gtk::Button = builder.get_object("generate_btn").unwrap(); 22 | 23 | // Outputs 24 | let message_output: gtk::Label = builder.get_object("message_output").unwrap(); 25 | let image_output: gtk::Image = builder.get_object("image_output").unwrap(); 26 | let image_output_clone = image_output.clone(); 27 | 28 | button.connect_clicked(move |_| { 29 | let is_dead = is_dead_switch.get_active(); 30 | if (is_dead) { 31 | message_output.set_text(&format!( 32 | "Dead: {}\n \\\n \\", 33 | message_input.get_text().unwrap().as_str() 34 | )); 35 | } else { 36 | message_output.set_text(&format!( 37 | "{}\n \\\n \\", 38 | message_input.get_text().unwrap().as_str() 39 | )); 40 | } 41 | image_output_clone.show(); 42 | }); 43 | 44 | window.show_all(); 45 | image_output.hide(); 46 | } 47 | 48 | fn main() { 49 | let application = gtk::Application::new("com.shinglyu.catsay-gui-glade", Default::default()) 50 | .expect("Failed to initialize GTK"); 51 | 52 | application.connect_activate(|app| { 53 | build_ui(app); 54 | }); 55 | 56 | application.run(&args().collect::>()); 57 | } 58 | -------------------------------------------------------------------------------- /gui/catsay-gui/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "atk" 5 | version = "0.6.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 9 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 10 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 11 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 12 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 13 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 14 | ] 15 | 16 | [[package]] 17 | name = "atk-sys" 18 | version = "0.8.0" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | dependencies = [ 21 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 22 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 23 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 24 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 25 | ] 26 | 27 | [[package]] 28 | name = "bitflags" 29 | version = "1.0.5" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | 32 | [[package]] 33 | name = "cairo-rs" 34 | version = "0.6.0" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | dependencies = [ 37 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 38 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 39 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 40 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 41 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 42 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 43 | ] 44 | 45 | [[package]] 46 | name = "cairo-sys-rs" 47 | version = "0.8.0" 48 | source = "registry+https://github.com/rust-lang/crates.io-index" 49 | dependencies = [ 50 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 51 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 53 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 54 | ] 55 | 56 | [[package]] 57 | name = "catsay-gui" 58 | version = "0.1.0" 59 | dependencies = [ 60 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 61 | "gtk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 62 | ] 63 | 64 | [[package]] 65 | name = "cc" 66 | version = "1.0.36" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | 69 | [[package]] 70 | name = "fragile" 71 | version = "0.3.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "gdk" 76 | version = "0.10.0" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | dependencies = [ 79 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 82 | "gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 91 | ] 92 | 93 | [[package]] 94 | name = "gdk-pixbuf" 95 | version = "0.6.0" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | dependencies = [ 98 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 100 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 103 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 104 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 105 | ] 106 | 107 | [[package]] 108 | name = "gdk-pixbuf-sys" 109 | version = "0.8.0" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | dependencies = [ 112 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 113 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 114 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 115 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 116 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 117 | ] 118 | 119 | [[package]] 120 | name = "gdk-sys" 121 | version = "0.8.0" 122 | source = "registry+https://github.com/rust-lang/crates.io-index" 123 | dependencies = [ 124 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 125 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 126 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 129 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 130 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 131 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 132 | ] 133 | 134 | [[package]] 135 | name = "gio" 136 | version = "0.6.0" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | dependencies = [ 139 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 140 | "fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 141 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 142 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 143 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 144 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 145 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 146 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 147 | ] 148 | 149 | [[package]] 150 | name = "gio-sys" 151 | version = "0.8.0" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | dependencies = [ 154 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 155 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 156 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 157 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 158 | ] 159 | 160 | [[package]] 161 | name = "glib" 162 | version = "0.7.1" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | dependencies = [ 165 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 166 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 167 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 168 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 169 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 170 | ] 171 | 172 | [[package]] 173 | name = "glib-sys" 174 | version = "0.8.0" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | dependencies = [ 177 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 178 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 179 | ] 180 | 181 | [[package]] 182 | name = "gobject-sys" 183 | version = "0.8.0" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | dependencies = [ 186 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 189 | ] 190 | 191 | [[package]] 192 | name = "gtk" 193 | version = "0.6.0" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | dependencies = [ 196 | "atk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 197 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 198 | "cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 199 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 200 | "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", 201 | "gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 202 | "gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 203 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 204 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 205 | "gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 206 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 207 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 208 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 209 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 210 | "gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 211 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 212 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 213 | "pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 215 | ] 216 | 217 | [[package]] 218 | name = "gtk-sys" 219 | version = "0.8.0" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | dependencies = [ 222 | "atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 223 | "cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 224 | "gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 225 | "gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 226 | "gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 227 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 228 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 229 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 230 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 231 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 232 | ] 233 | 234 | [[package]] 235 | name = "lazy_static" 236 | version = "1.3.0" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | 239 | [[package]] 240 | name = "libc" 241 | version = "0.2.54" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | 244 | [[package]] 245 | name = "pango" 246 | version = "0.6.0" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | dependencies = [ 249 | "bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 254 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 255 | "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 256 | ] 257 | 258 | [[package]] 259 | name = "pango-sys" 260 | version = "0.8.0" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | dependencies = [ 263 | "glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 265 | "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", 266 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 267 | ] 268 | 269 | [[package]] 270 | name = "pkg-config" 271 | version = "0.3.14" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | 274 | [[package]] 275 | name = "winapi" 276 | version = "0.3.7" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | dependencies = [ 279 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 280 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 281 | ] 282 | 283 | [[package]] 284 | name = "winapi-i686-pc-windows-gnu" 285 | version = "0.4.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | 288 | [[package]] 289 | name = "winapi-x86_64-pc-windows-gnu" 290 | version = "0.4.0" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | 293 | [metadata] 294 | "checksum atk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ce8fd2055aa2ce617754c5a701682a06b4b57093cbbcbd8f068622a8debae96" 295 | "checksum atk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83744274abbcc2242f845a25cf84b9adb5991eaecc8f7c67cffd69ea636f4ff8" 296 | "checksum bitflags 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bd1fa8ad26490b0a5cfec99089952250301b6716cdeaa7c9ab229598fb82ab66" 297 | "checksum cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e09d8a818b2ccc8983f04d95a9350c3cf8d24cc456cedca3b88fa3a81fdc0e2" 298 | "checksum cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fa13914fdc013387afa771f554f2f71d6ae931f4e5be9246c337d60c3dc484" 299 | "checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d" 300 | "checksum fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9" 301 | "checksum gdk 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c229b642a3cf701f92246b131fda2eaabaa5f44f4a255dee65939ebd0ab0141" 302 | "checksum gdk-pixbuf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a1bcb11b461ff5638f6bf03c9f173d3dc250eabc8e57a60644b6f529d3a7c91" 303 | "checksum gdk-pixbuf-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10e1115ca451907b6d775fc0392641d14c89277662d98828412fb68555e7e8c8" 304 | "checksum gdk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "458dc6243bdda4aa1693f5f18231f55b98e9c99c50b3b9bd673cf461ef1710ea" 305 | "checksum gio 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff120a666f4a0f41cca7554fbac82defc2562e90eccf3b26a30e6461fa1bbde8" 306 | "checksum gio-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04957c40df00dd72f7c9ec8e382b01ff8ed4a904fcd2fa608b7ae7fbaccfda8f" 307 | "checksum glib 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e8fdc159c196a5dfa53a92929ac4c10c8a6637ffb43951f3fff89c2cd2365" 308 | "checksum glib-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bda542f3caee39a027638e9644ff89204101ad916fd7370b585ad2c5fc97e61" 309 | "checksum gobject-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23e05a14290d3dc255223cba51db4b0f3da438d5250657996fa99b2a30faf43e" 310 | "checksum gtk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b52cfbd8c3e4a000c8374676352f3850c2d62c0f42ef0a993e5d3fcf47e0be64" 311 | "checksum gtk-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "849835f05d46f605b00ee9fefb6d5921238c570af406f35ee7426ed01cd6795c" 312 | "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 313 | "checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" 314 | "checksum pango 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e36b55d7cd522bd183efeb3dfabc547bda1f26eadf8a1241dac09ab3fd3242c" 315 | "checksum pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "747ab9cd4d537e6dc5ef0e4308c10dde8b706673b0237fed4e056b8d2c0b23c8" 316 | "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" 317 | "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" 318 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 319 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 320 | -------------------------------------------------------------------------------- /gui/catsay-gui/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "catsay-gui" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | gio = "0.6.0" 9 | 10 | [dependencies.gtk] 11 | version = "0.6.0" # the gtk crate version 12 | features = ["v3_18"] # system gtk version 13 | -------------------------------------------------------------------------------- /gui/catsay-gui/README.md: -------------------------------------------------------------------------------- 1 | # Prerequisite 2 | Reference: https://gtk-rs.org/docs-src/requirements.html 3 | ## Ubuntu and Debian 4 | 5 | sudo apt-get install libgtk-3-dev 6 | // Checking which version was installed 7 | dpkg -l libgtk-3-0 8 | 9 | # Image credit: 10 | * https://pixabay.com/photos/cat-kitten-sit-isolated-red-white-2669554/ 11 | -------------------------------------------------------------------------------- /gui/catsay-gui/images/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/gui/catsay-gui/images/cat.png -------------------------------------------------------------------------------- /gui/catsay-gui/layout.glade: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | False 7 | 8 | 9 | True 10 | False 11 | vertical 12 | 13 | 14 | True 15 | False 16 | vertical 17 | 18 | 19 | True 20 | False 21 | What does the cat say: 22 | 23 | 24 | False 25 | True 26 | 0 27 | 28 | 29 | 30 | 31 | True 32 | True 33 | 34 | 35 | False 36 | True 37 | 1 38 | 39 | 40 | 41 | 42 | Generate 43 | True 44 | True 45 | True 46 | 47 | 48 | False 49 | True 50 | 2 51 | 52 | 53 | 54 | 55 | False 56 | True 57 | 0 58 | 59 | 60 | 61 | 62 | True 63 | False 64 | vertical 65 | 66 | 67 | True 68 | False 69 | end 70 | 71 | 72 | False 73 | True 74 | 0 75 | 76 | 77 | 78 | 79 | True 80 | False 81 | cat.png 82 | 83 | 84 | False 85 | True 86 | 1 87 | 88 | 89 | 90 | 91 | False 92 | True 93 | 1 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /gui/catsay-gui/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate gio; 2 | extern crate gtk; 3 | 4 | use gio::prelude::*; 5 | use gtk::prelude::*; 6 | use gtk::{Application, ApplicationWindow, Box, Image, Label, Orientation}; 7 | use std::env; 8 | 9 | fn main() { 10 | // Application need an ID 11 | let app = Application::new("com.shinglyu.catsay-gui", gio::ApplicationFlags::empty()) 12 | .expect("Failed to initialize GTK."); 13 | 14 | // Callback when the app starts 15 | app.connect_startup(|app| { 16 | let window = ApplicationWindow::new(app); 17 | window.set_title("Catsay"); 18 | window.set_default_size(350, 70); 19 | 20 | window.connect_delete_event(|win, _| { 21 | win.destroy(); 22 | Inhibit(false) 23 | }); 24 | let layout_box = Box::new(Orientation::Vertical, 0); 25 | 26 | let label = Label::new("Meow!\n \\\n \\"); 27 | //label.set_xalign(0.0); 28 | layout_box.add(&label); 29 | 30 | let cat_image = Image::new_from_file("./images/cat.png"); 31 | layout_box.add(&cat_image); 32 | window.add(&layout_box); 33 | 34 | window.show_all(); 35 | }); 36 | 37 | // Callback when the app activates, do nothing 38 | app.connect_activate(|_| {}); 39 | // Run the app 40 | app.run(&env::args().collect::>()); 41 | } 42 | -------------------------------------------------------------------------------- /gui/catsay-tui/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "arc-swap" 5 | version = "0.3.11" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | 8 | [[package]] 9 | name = "array-macro" 10 | version = "1.0.3" 11 | source = "registry+https://github.com/rust-lang/crates.io-index" 12 | 13 | [[package]] 14 | name = "catsay-tui" 15 | version = "0.1.0" 16 | dependencies = [ 17 | "cursive 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", 18 | ] 19 | 20 | [[package]] 21 | name = "cc" 22 | version = "1.0.35" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | 25 | [[package]] 26 | name = "cfg-if" 27 | version = "0.1.7" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | 30 | [[package]] 31 | name = "chrono" 32 | version = "0.4.6" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | dependencies = [ 35 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 36 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 37 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 38 | ] 39 | 40 | [[package]] 41 | name = "crossbeam-channel" 42 | version = "0.3.8" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | dependencies = [ 45 | "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 46 | "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", 47 | ] 48 | 49 | [[package]] 50 | name = "crossbeam-utils" 51 | version = "0.6.5" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | dependencies = [ 54 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 55 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 56 | ] 57 | 58 | [[package]] 59 | name = "cursive" 60 | version = "0.11.2" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | dependencies = [ 63 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 64 | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 65 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 66 | "enum-map 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 67 | "enumset 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", 68 | "hashbrown 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 69 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 70 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 71 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 72 | "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 73 | "ncurses 5.99.0 (registry+https://github.com/rust-lang/crates.io-index)", 74 | "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 75 | "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 76 | "signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 78 | "toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 79 | "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 82 | ] 83 | 84 | [[package]] 85 | name = "enum-map" 86 | version = "0.5.0" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | dependencies = [ 89 | "enum-map-derive 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "enum-map-internals 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 91 | ] 92 | 93 | [[package]] 94 | name = "enum-map-derive" 95 | version = "0.4.1" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | dependencies = [ 98 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", 100 | "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", 101 | ] 102 | 103 | [[package]] 104 | name = "enum-map-internals" 105 | version = "0.1.2" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | dependencies = [ 108 | "array-macro 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 109 | ] 110 | 111 | [[package]] 112 | name = "enumset" 113 | version = "0.3.18" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | dependencies = [ 116 | "enumset_derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 117 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 118 | ] 119 | 120 | [[package]] 121 | name = "enumset_derive" 122 | version = "0.3.1" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | dependencies = [ 125 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 126 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", 128 | ] 129 | 130 | [[package]] 131 | name = "hashbrown" 132 | version = "0.2.2" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | 135 | [[package]] 136 | name = "kernel32-sys" 137 | version = "0.2.2" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | dependencies = [ 140 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 141 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 142 | ] 143 | 144 | [[package]] 145 | name = "lazy_static" 146 | version = "1.3.0" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | 149 | [[package]] 150 | name = "libc" 151 | version = "0.2.51" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | 154 | [[package]] 155 | name = "log" 156 | version = "0.4.6" 157 | source = "registry+https://github.com/rust-lang/crates.io-index" 158 | dependencies = [ 159 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 160 | ] 161 | 162 | [[package]] 163 | name = "maplit" 164 | version = "1.0.1" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | 167 | [[package]] 168 | name = "ncurses" 169 | version = "5.99.0" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | dependencies = [ 172 | "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", 173 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 174 | "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 175 | ] 176 | 177 | [[package]] 178 | name = "num" 179 | version = "0.2.0" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | dependencies = [ 182 | "num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 183 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 184 | "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 185 | "num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 186 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 187 | ] 188 | 189 | [[package]] 190 | name = "num-complex" 191 | version = "0.2.1" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | dependencies = [ 194 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 195 | ] 196 | 197 | [[package]] 198 | name = "num-integer" 199 | version = "0.1.39" 200 | source = "registry+https://github.com/rust-lang/crates.io-index" 201 | dependencies = [ 202 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 203 | ] 204 | 205 | [[package]] 206 | name = "num-iter" 207 | version = "0.1.37" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | dependencies = [ 210 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 211 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 212 | ] 213 | 214 | [[package]] 215 | name = "num-rational" 216 | version = "0.2.1" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | dependencies = [ 219 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 220 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 221 | ] 222 | 223 | [[package]] 224 | name = "num-traits" 225 | version = "0.2.6" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | 228 | [[package]] 229 | name = "owning_ref" 230 | version = "0.4.0" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | dependencies = [ 233 | "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 234 | ] 235 | 236 | [[package]] 237 | name = "pkg-config" 238 | version = "0.3.14" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | 241 | [[package]] 242 | name = "proc-macro2" 243 | version = "0.4.27" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | dependencies = [ 246 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 247 | ] 248 | 249 | [[package]] 250 | name = "quote" 251 | version = "0.6.12" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | dependencies = [ 254 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 255 | ] 256 | 257 | [[package]] 258 | name = "redox_syscall" 259 | version = "0.1.54" 260 | source = "registry+https://github.com/rust-lang/crates.io-index" 261 | 262 | [[package]] 263 | name = "serde" 264 | version = "1.0.90" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | 267 | [[package]] 268 | name = "signal-hook" 269 | version = "0.1.8" 270 | source = "registry+https://github.com/rust-lang/crates.io-index" 271 | dependencies = [ 272 | "arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", 273 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 274 | ] 275 | 276 | [[package]] 277 | name = "smallvec" 278 | version = "0.6.9" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | 281 | [[package]] 282 | name = "stable_deref_trait" 283 | version = "1.1.1" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | 286 | [[package]] 287 | name = "syn" 288 | version = "0.14.9" 289 | source = "registry+https://github.com/rust-lang/crates.io-index" 290 | dependencies = [ 291 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 292 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", 293 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 294 | ] 295 | 296 | [[package]] 297 | name = "syn" 298 | version = "0.15.32" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | dependencies = [ 301 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 302 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", 303 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 304 | ] 305 | 306 | [[package]] 307 | name = "term_size" 308 | version = "0.3.1" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | dependencies = [ 311 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 312 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 313 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 314 | ] 315 | 316 | [[package]] 317 | name = "time" 318 | version = "0.1.42" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | dependencies = [ 321 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 322 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 323 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 324 | ] 325 | 326 | [[package]] 327 | name = "toml" 328 | version = "0.5.0" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | dependencies = [ 331 | "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", 332 | ] 333 | 334 | [[package]] 335 | name = "unicode-segmentation" 336 | version = "1.2.1" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | 339 | [[package]] 340 | name = "unicode-width" 341 | version = "0.1.5" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | 344 | [[package]] 345 | name = "unicode-xid" 346 | version = "0.1.0" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | 349 | [[package]] 350 | name = "winapi" 351 | version = "0.2.8" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | 354 | [[package]] 355 | name = "winapi" 356 | version = "0.3.7" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | dependencies = [ 359 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 360 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 361 | ] 362 | 363 | [[package]] 364 | name = "winapi-build" 365 | version = "0.1.1" 366 | source = "registry+https://github.com/rust-lang/crates.io-index" 367 | 368 | [[package]] 369 | name = "winapi-i686-pc-windows-gnu" 370 | version = "0.4.0" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | 373 | [[package]] 374 | name = "winapi-x86_64-pc-windows-gnu" 375 | version = "0.4.0" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | 378 | [[package]] 379 | name = "xi-unicode" 380 | version = "0.1.0" 381 | source = "registry+https://github.com/rust-lang/crates.io-index" 382 | 383 | [metadata] 384 | "checksum arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "bc4662175ead9cd84451d5c35070517777949a2ed84551764129cedb88384841" 385 | "checksum array-macro 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c4ff37a25fb442a1fecfd399be0dde685558bca30fb998420532889a36852d2" 386 | "checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83" 387 | "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" 388 | "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" 389 | "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" 390 | "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" 391 | "checksum cursive 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c4efbb2a4c98f3b197c6d5ee5fb6fdab1e50e5314204c9c22d30cdcd7e760194" 392 | "checksum enum-map 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ccd9b2d5e0eb5c2ff851791e2af90ab4531b1168cfc239d1c0bf467e60ba3c89" 393 | "checksum enum-map-derive 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "153f6e8a8b2868e2fedf921b165f30229edcccb74d6a9bb1ccf0480ef61cd07e" 394 | "checksum enum-map-internals 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38b0bacf3ea7aba18ce84032efc3f0fa29f5c814048b742ab3e64d07d83ac3e8" 395 | "checksum enumset 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "de07e911efad7a0745917989e52da0a61d46b6038974453a2891f4e9a9669031" 396 | "checksum enumset_derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d78d2002f26264ab31468cab442c1e377842a3b458458b7671c3fc39bdb477f2" 397 | "checksum hashbrown 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "61e4900fa4e80b3d15c78a08ec8a08433246063fa7577e7b2c6426b3b21b1f79" 398 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 399 | "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 400 | "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" 401 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" 402 | "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" 403 | "checksum ncurses 5.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82" 404 | "checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db" 405 | "checksum num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "107b9be86cd2481930688277b675b0114578227f034674726605b8a482d8baf8" 406 | "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" 407 | "checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" 408 | "checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10" 409 | "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 410 | "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" 411 | "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" 412 | "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" 413 | "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" 414 | "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" 415 | "checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" 416 | "checksum signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "97a47ae722318beceb0294e6f3d601205a1e6abaa4437d9d33e3a212233e3021" 417 | "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" 418 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" 419 | "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" 420 | "checksum syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)" = "846620ec526c1599c070eff393bfeeeb88a93afa2513fc3b49f1fea84cf7b0ed" 421 | "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" 422 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" 423 | "checksum toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c5890a989fa47ecdc7bcb4c63a77a82c18f306714104b1decfd722db17b39e" 424 | "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" 425 | "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" 426 | "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 427 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 428 | "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" 429 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 430 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 431 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 432 | "checksum xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12ea8eda4b1eb72f02d148402e23832d56a33f55d8c1b2d5bcdde91d79d47cb1" 433 | -------------------------------------------------------------------------------- /gui/catsay-tui/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "catsay-tui" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cursive = "0.11.2" 9 | -------------------------------------------------------------------------------- /gui/catsay-tui/README.md: -------------------------------------------------------------------------------- 1 | # Install ncurses 2 | * Ubuntu: `apt-get install libncursesw5-dev` 3 | -------------------------------------------------------------------------------- /gui/catsay-tui/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate cursive; 2 | 3 | use cursive::traits::Identifiable; 4 | use cursive::views::{Checkbox, Dialog, EditView, ListView, TextView}; 5 | use cursive::Cursive; 6 | 7 | struct CatsayOptions<'a> { 8 | message: &'a str, 9 | dead: bool, 10 | } 11 | 12 | fn input_step(siv: &mut Cursive) { 13 | siv.add_layer( 14 | Dialog::new() 15 | .title("Please fill out the form for the cat") 16 | .content( 17 | ListView::new() 18 | .child("Message:", EditView::new().with_id("message")) 19 | .child("Dead?", Checkbox::new().with_id("dead")), 20 | ) 21 | .button("OK", |s| { 22 | let message = s 23 | .call_on_id("message", |t: &mut EditView| t.get_content()) 24 | .unwrap(); 25 | let is_dead = s 26 | .call_on_id("dead", |t: &mut Checkbox| t.is_checked()) 27 | .unwrap(); 28 | let options = CatsayOptions { 29 | message: &message, 30 | dead: is_dead, 31 | }; 32 | result_step(s, &options) 33 | }), 34 | ); 35 | } 36 | 37 | // TODO: change this to options 38 | fn result_step(siv: &mut Cursive, options: &CatsayOptions) { 39 | let eye = if options.dead { "x" } else { "o" }; 40 | 41 | let cat_text = format!( 42 | "{msg} 43 | \\ 44 | \\ 45 | /\\_/\\ 46 | ( {eye} {eye} ) 47 | =( I )=", 48 | msg = options.message, 49 | eye = eye 50 | ); 51 | 52 | siv.pop_layer(); 53 | siv.add_layer( 54 | Dialog::around(TextView::new(cat_text)) 55 | .title("The cat says...") 56 | .button("OK", |s| s.quit()), 57 | ); 58 | } 59 | 60 | fn main() { 61 | let mut siv = Cursive::default(); 62 | 63 | input_step(&mut siv); 64 | 65 | siv.run(); 66 | } 67 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "ansi_term" 5 | version = "0.11.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "atty" 13 | version = "0.2.13" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | dependencies = [ 16 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 17 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 18 | ] 19 | 20 | [[package]] 21 | name = "autocfg" 22 | version = "0.1.6" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | 25 | [[package]] 26 | name = "bitflags" 27 | version = "1.2.1" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | 30 | [[package]] 31 | name = "bstr" 32 | version = "0.2.8" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | dependencies = [ 35 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 36 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 37 | "regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 38 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", 39 | ] 40 | 41 | [[package]] 42 | name = "byteorder" 43 | version = "1.3.2" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | 46 | [[package]] 47 | name = "c2-chacha" 48 | version = "0.2.2" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | dependencies = [ 51 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 53 | ] 54 | 55 | [[package]] 56 | name = "cat-breed-k-means" 57 | version = "0.1.0" 58 | dependencies = [ 59 | "csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 60 | "gnuplot 0.0.31 (registry+https://github.com/rust-lang/crates.io-index)", 61 | "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 62 | "rand_distr 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 63 | "rusty-machine 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", 64 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", 65 | "structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 66 | "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", 67 | ] 68 | 69 | [[package]] 70 | name = "cfg-if" 71 | version = "0.1.9" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "clap" 76 | version = "2.33.0" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | dependencies = [ 79 | "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 82 | "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 86 | ] 87 | 88 | [[package]] 89 | name = "csv" 90 | version = "1.1.1" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | dependencies = [ 93 | "bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 94 | "csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 95 | "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 96 | "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 97 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", 98 | ] 99 | 100 | [[package]] 101 | name = "csv-core" 102 | version = "0.1.6" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | dependencies = [ 105 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 106 | ] 107 | 108 | [[package]] 109 | name = "fuchsia-cprng" 110 | version = "0.1.1" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | 113 | [[package]] 114 | name = "getrandom" 115 | version = "0.1.12" 116 | source = "registry+https://github.com/rust-lang/crates.io-index" 117 | dependencies = [ 118 | "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 119 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 120 | "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 121 | ] 122 | 123 | [[package]] 124 | name = "gnuplot" 125 | version = "0.0.31" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | 128 | [[package]] 129 | name = "heck" 130 | version = "0.3.1" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | dependencies = [ 133 | "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 134 | ] 135 | 136 | [[package]] 137 | name = "itoa" 138 | version = "0.4.4" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | 141 | [[package]] 142 | name = "lazy_static" 143 | version = "1.4.0" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | 146 | [[package]] 147 | name = "libc" 148 | version = "0.2.62" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | 151 | [[package]] 152 | name = "matrixmultiply" 153 | version = "0.1.15" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | dependencies = [ 156 | "rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 157 | ] 158 | 159 | [[package]] 160 | name = "memchr" 161 | version = "2.2.1" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | dependencies = [ 164 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 165 | ] 166 | 167 | [[package]] 168 | name = "num" 169 | version = "0.1.42" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | dependencies = [ 172 | "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 173 | "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 174 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 175 | ] 176 | 177 | [[package]] 178 | name = "num-integer" 179 | version = "0.1.41" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | dependencies = [ 182 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 183 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 184 | ] 185 | 186 | [[package]] 187 | name = "num-iter" 188 | version = "0.1.39" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | dependencies = [ 191 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 192 | "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 193 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 194 | ] 195 | 196 | [[package]] 197 | name = "num-traits" 198 | version = "0.2.8" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | dependencies = [ 201 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 202 | ] 203 | 204 | [[package]] 205 | name = "ppv-lite86" 206 | version = "0.2.5" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | 209 | [[package]] 210 | name = "proc-macro-error" 211 | version = "0.2.6" 212 | source = "registry+https://github.com/rust-lang/crates.io-index" 213 | dependencies = [ 214 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 215 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 216 | "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 217 | ] 218 | 219 | [[package]] 220 | name = "proc-macro2" 221 | version = "1.0.6" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | dependencies = [ 224 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 225 | ] 226 | 227 | [[package]] 228 | name = "quote" 229 | version = "1.0.2" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | dependencies = [ 232 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 233 | ] 234 | 235 | [[package]] 236 | name = "rand" 237 | version = "0.3.23" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | dependencies = [ 240 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 241 | "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 242 | ] 243 | 244 | [[package]] 245 | name = "rand" 246 | version = "0.4.6" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | dependencies = [ 249 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 254 | ] 255 | 256 | [[package]] 257 | name = "rand" 258 | version = "0.7.0" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | dependencies = [ 261 | "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 262 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 263 | "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 265 | "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 266 | ] 267 | 268 | [[package]] 269 | name = "rand_chacha" 270 | version = "0.2.1" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | dependencies = [ 273 | "c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 274 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 275 | ] 276 | 277 | [[package]] 278 | name = "rand_core" 279 | version = "0.3.1" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | dependencies = [ 282 | "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 283 | ] 284 | 285 | [[package]] 286 | name = "rand_core" 287 | version = "0.4.2" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | 290 | [[package]] 291 | name = "rand_core" 292 | version = "0.5.1" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | dependencies = [ 295 | "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 296 | ] 297 | 298 | [[package]] 299 | name = "rand_distr" 300 | version = "0.2.1" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | dependencies = [ 303 | "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 304 | ] 305 | 306 | [[package]] 307 | name = "rand_hc" 308 | version = "0.2.0" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | dependencies = [ 311 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 312 | ] 313 | 314 | [[package]] 315 | name = "rawpointer" 316 | version = "0.1.0" 317 | source = "registry+https://github.com/rust-lang/crates.io-index" 318 | 319 | [[package]] 320 | name = "rdrand" 321 | version = "0.4.0" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | dependencies = [ 324 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 325 | ] 326 | 327 | [[package]] 328 | name = "regex-automata" 329 | version = "0.1.8" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | dependencies = [ 332 | "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 333 | ] 334 | 335 | [[package]] 336 | name = "rulinalg" 337 | version = "0.3.7" 338 | source = "registry+https://github.com/rust-lang/crates.io-index" 339 | dependencies = [ 340 | "matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", 341 | "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 342 | ] 343 | 344 | [[package]] 345 | name = "rusty-machine" 346 | version = "0.5.4" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | dependencies = [ 349 | "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 350 | "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", 351 | "rulinalg 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 352 | ] 353 | 354 | [[package]] 355 | name = "ryu" 356 | version = "1.0.0" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | 359 | [[package]] 360 | name = "serde" 361 | version = "1.0.103" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | dependencies = [ 364 | "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", 365 | ] 366 | 367 | [[package]] 368 | name = "serde_derive" 369 | version = "1.0.103" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | dependencies = [ 372 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 373 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 374 | "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 375 | ] 376 | 377 | [[package]] 378 | name = "strsim" 379 | version = "0.8.0" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | 382 | [[package]] 383 | name = "structopt" 384 | version = "0.3.5" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | dependencies = [ 387 | "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", 388 | "structopt-derive 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 389 | ] 390 | 391 | [[package]] 392 | name = "structopt-derive" 393 | version = "0.3.5" 394 | source = "registry+https://github.com/rust-lang/crates.io-index" 395 | dependencies = [ 396 | "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 398 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 399 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 400 | "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 401 | ] 402 | 403 | [[package]] 404 | name = "syn" 405 | version = "1.0.11" 406 | source = "registry+https://github.com/rust-lang/crates.io-index" 407 | dependencies = [ 408 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 409 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 410 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 411 | ] 412 | 413 | [[package]] 414 | name = "textwrap" 415 | version = "0.11.0" 416 | source = "registry+https://github.com/rust-lang/crates.io-index" 417 | dependencies = [ 418 | "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 419 | ] 420 | 421 | [[package]] 422 | name = "toml" 423 | version = "0.5.5" 424 | source = "registry+https://github.com/rust-lang/crates.io-index" 425 | dependencies = [ 426 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", 427 | ] 428 | 429 | [[package]] 430 | name = "unicode-segmentation" 431 | version = "1.6.0" 432 | source = "registry+https://github.com/rust-lang/crates.io-index" 433 | 434 | [[package]] 435 | name = "unicode-width" 436 | version = "0.1.7" 437 | source = "registry+https://github.com/rust-lang/crates.io-index" 438 | 439 | [[package]] 440 | name = "unicode-xid" 441 | version = "0.2.0" 442 | source = "registry+https://github.com/rust-lang/crates.io-index" 443 | 444 | [[package]] 445 | name = "vec_map" 446 | version = "0.8.1" 447 | source = "registry+https://github.com/rust-lang/crates.io-index" 448 | 449 | [[package]] 450 | name = "wasi" 451 | version = "0.7.0" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | 454 | [[package]] 455 | name = "winapi" 456 | version = "0.3.8" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | dependencies = [ 459 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 460 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 461 | ] 462 | 463 | [[package]] 464 | name = "winapi-i686-pc-windows-gnu" 465 | version = "0.4.0" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | 468 | [[package]] 469 | name = "winapi-x86_64-pc-windows-gnu" 470 | version = "0.4.0" 471 | source = "registry+https://github.com/rust-lang/crates.io-index" 472 | 473 | [metadata] 474 | "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 475 | "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" 476 | "checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" 477 | "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 478 | "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" 479 | "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 480 | "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" 481 | "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" 482 | "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" 483 | "checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" 484 | "checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c" 485 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 486 | "checksum getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571" 487 | "checksum gnuplot 0.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "18a907dc810202b800898a3059eba489404c7f232f8e141500122a86b173bd7f" 488 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 489 | "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" 490 | "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 491 | "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" 492 | "checksum matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "dcad67dcec2d58ff56f6292582377e6921afdf3bfbd533e26fb8900ae575e002" 493 | "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 494 | "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" 495 | "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" 496 | "checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e" 497 | "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" 498 | "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" 499 | "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" 500 | "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" 501 | "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" 502 | "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" 503 | "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" 504 | "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" 505 | "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" 506 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 507 | "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 508 | "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 509 | "checksum rand_distr 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c37e54d811c5a51195156444e298a98ba57df6dca1e511f34d4791993883b921" 510 | "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 511 | "checksum rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019" 512 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 513 | "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" 514 | "checksum rulinalg 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5670ce3717deb2d4436bdb29f07c549b56595f1fd8af1ca4682f1c1b1ac57f86" 515 | "checksum rusty-machine 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "dee5358236bbd0835aeee9a8b04c8b9b0aaea243a1a1a71253957b4606fb9171" 516 | "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" 517 | "checksum serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702" 518 | "checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0" 519 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 520 | "checksum structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "30b3a3e93f5ad553c38b3301c8a0a0cec829a36783f6a0c467fc4bf553a5f5bf" 521 | "checksum structopt-derive 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea692d40005b3ceba90a9fe7a78fa8d4b82b0ce627eebbffc329aab850f3410e" 522 | "checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" 523 | "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 524 | "checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" 525 | "checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" 526 | "checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" 527 | "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" 528 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" 529 | "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" 530 | "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 531 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 532 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 533 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cat-breed-k-means" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rusty-machine = "0.5.4" 9 | csv = "1.1" 10 | rand = "0.7.0" 11 | rand_distr = "0.2.1" 12 | gnuplot = "0.0.31" 13 | toml = "0.5.5" 14 | serde = { version = "1.0.103", features = ["derive"] } 15 | structopt = "0.3.5" 16 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/README.md: -------------------------------------------------------------------------------- 1 | # Generate samples 2 | 3 | cargo run --bin generate 4 | 5 | # Plotting 6 | 7 | sudo apt-get install gnuplot 8 | cargo run --bin plot 9 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/cat_breed.md: -------------------------------------------------------------------------------- 1 | Persian 2 | Details 3 | Height: 4 | 8.0”-10.0" | 20-25 cm 5 | Length: 6 | 14.5”-17.5” | 37-44 cm 7 | Weight: 8 | 7-12 lb | 3-5 kg 9 | Body: Round face, short muzzle, stocky, short legs, long hair 10 | Color: White (classic), variety of colors and patterns 11 | Temperament: Placid, relaxed, shy 12 | 13 | Lifespan 14 | 10-18 years 15 | Drawings include: 16 | Persian Cat side profile (walking), front (sitting), back (sitting), side (laying down) 17 | 18 | 19 | British short hair 20 | Details 21 | Height: 22 | 12.0”-14.0” | 30-46 cm 23 | Length: 24 | 22.0”-25.0” | 56-64 cm 25 | Weight: 26 | 7-17 lb | 3-8 kg 27 | Body: Big bodied, chunky, dense coat, medium tail, broad face 28 | Color: Solid blue-gray with copper eyes (British Blue) 29 | Temperament: Relaxed, affectionate, dignified, devoted 30 | 31 | Lifespan 32 | 15-20 years 33 | Drawings include: 34 | British Shorthair Cat side profile (walking), front (sitting), back (sitting), side (laying down) 35 | 36 | 37 | 38 | Ragdoll cat 39 | Details 40 | Height: 41 | 9.0”-11.0" | 23-28 cm 42 | Length: 43 | 17.0”-21.0” | 43-53 cm 44 | Weight: 45 | 8-20 lb | 4-9 kg 46 | Body: Large, muscular, semi-longhair, soft and silky coat, blue eyes 47 | Color: Seal, chocolate, flame, blue, lilac, cream 48 | Temperament: Lovable, docile, calm 49 | 50 | Lifespan 51 | 12-15 years 52 | Drawings include: 53 | Ragdoll Cat side profile (walking), side (sitting), front (sitting), side (laying down) 54 | 55 | 56 | ------ 57 | 58 | https://www.dimensions.guide/legal 59 | All drawings, images, information, and dimensions published on Dimensions.Guide can be used and referenced for free. You can use them for commercial and noncommercial purposes. You do not need to ask permission from or provide credit to Dimensions.Guide to reference our drawings, although it is appreciated when possible. 60 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/config/generate.toml: -------------------------------------------------------------------------------- 1 | centroids = [ # Height, length 2 | 22.5, 40.5, # persian 3 | 38.0, 50.0, # British short hair 4 | 25.5, 48.0, # Ragdoll 5 | ] 6 | noise = 1.8 7 | samples_per_centroid = 2000 8 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/config/generate2.toml: -------------------------------------------------------------------------------- 1 | centroids = [ # Height, length 2 | 22.5, 40.5, # persian 3 | 38.0, 50.0, # British short hair 4 | 25.5, 48.0, # Ragdoll 5 | ] 6 | noise = 100 7 | samples_per_centroid = 2 8 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/run.sh: -------------------------------------------------------------------------------- 1 | cargo run --bin generate > test_data.csv && 2 | cat test_data.csv | cargo run --bin plot && 3 | cat test_data.csv | cargo run --bin cluster > result.csv && 4 | cat result.csv | cargo run --bin plot_results 5 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/src/bin/cluster.rs: -------------------------------------------------------------------------------- 1 | extern crate rusty_machine; 2 | extern crate rand; 3 | 4 | use std::io; 5 | use std::error::Error; 6 | 7 | use rusty_machine::linalg::{Matrix, BaseMatrix}; 8 | use rusty_machine::learning::k_means::KMeansClassifier; 9 | use rusty_machine::learning::UnSupModel; 10 | 11 | const CLUSTER_COUNT: usize = 3; 12 | 13 | fn read_data_from_stdin() -> Result, Box> { 14 | let mut reader = csv::Reader::from_reader(io::stdin()); 15 | let mut data: Vec= vec!(); 16 | for result in reader.records() { 17 | let record = result?; 18 | data.push(record[0].parse().unwrap()); 19 | data.push(record[1].parse().unwrap()); 20 | } 21 | 22 | Ok(Matrix::new(&data.len() / 2, 2, data)) 23 | } 24 | 25 | fn export_result_to_stdout(samples: Matrix, classes: Vec) -> Result<(), Box> { 26 | let mut writer = csv::Writer::from_writer(io::stdout()); 27 | writer.write_record(&["height", "length", "class"])?; 28 | for sample in samples.iter_rows().zip(classes) { 29 | writer.serialize(sample)?; 30 | } 31 | Ok(()) 32 | } 33 | 34 | fn main() { 35 | 36 | let samples = read_data_from_stdin().unwrap(); 37 | 38 | let mut model = KMeansClassifier::new(CLUSTER_COUNT); 39 | model.train(&samples).unwrap(); 40 | 41 | let classes = model.predict(&samples).unwrap(); 42 | 43 | export_result_to_stdout(samples, classes.into_vec()).unwrap(); 44 | } 45 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/src/bin/generate.rs: -------------------------------------------------------------------------------- 1 | extern crate toml; 2 | extern crate rusty_machine; 3 | extern crate rand; 4 | 5 | use rusty_machine::linalg::{Matrix, BaseMatrix}; 6 | 7 | use rand::thread_rng; 8 | use rand::distributions::Distribution; // for using .sample() 9 | use rand_distr::Normal; // splitted from rand since 0.7 10 | use serde::Deserialize; 11 | use std::io; 12 | use std::vec::Vec; 13 | use std::fs::read_to_string; 14 | use structopt::StructOpt; 15 | 16 | fn generate_data(centroids: &Matrix, 17 | points_per_centroid: usize, 18 | noise: f64) 19 | -> Matrix { 20 | assert!(centroids.cols() > 0, "centroids cannot be empty."); 21 | assert!(centroids.rows() > 0, "centroids cannot be empty."); 22 | assert!(noise >= 0f64, "noise must be non-negative."); 23 | let mut raw_cluster_data = Vec::with_capacity(centroids.rows() * points_per_centroid * 24 | centroids.cols()); 25 | 26 | let mut rng = thread_rng(); 27 | let normal_rv = Normal::new(0f64, noise).unwrap(); 28 | 29 | for _ in 0..points_per_centroid { 30 | // generate points from each centroid 31 | for centroid in centroids.iter_rows() { 32 | // generate a point randomly around the centroid 33 | let mut point = Vec::with_capacity(centroids.cols()); 34 | for feature in centroid.iter() { 35 | point.push(feature + normal_rv.sample(&mut rng)); 36 | } 37 | 38 | // push point to raw_cluster_data 39 | raw_cluster_data.extend(point); 40 | } 41 | } 42 | 43 | Matrix::new(centroids.rows() * points_per_centroid, 44 | centroids.cols(), 45 | raw_cluster_data) 46 | } 47 | 48 | #[derive(Debug, Deserialize)] 49 | struct Config { 50 | centroids: [f64;6], 51 | noise: f64, 52 | samples_per_centroid: usize, 53 | } 54 | 55 | #[derive(StructOpt)] 56 | struct Options { 57 | #[structopt(short = "c", long = "config-file", 58 | parse(from_os_str))] 59 | /// Configuration file TOML 60 | config_file_path: std::path::PathBuf, 61 | } 62 | 63 | fn main() -> Result<(), std::io::Error> { 64 | 65 | let options = Options::from_args(); 66 | let toml_config_str = read_to_string(options.config_file_path)?; 67 | let config: Config = toml::from_str(&toml_config_str)?; 68 | 69 | let centroids = Matrix::new(3, 2, config.centroids.to_vec()); 70 | 71 | let samples = generate_data(¢roids, config.samples_per_centroid, config.noise); 72 | 73 | let mut writer = csv::Writer::from_writer(io::stdout()); 74 | writer.write_record(&["height", "length"])?; 75 | for sample in samples.iter_rows() { 76 | writer.serialize(sample)?; 77 | } 78 | Ok(()) 79 | } 80 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/src/bin/plot.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::io; 3 | use gnuplot::{Figure, Caption, Graph}; 4 | use gnuplot::AxesCommon; 5 | 6 | fn main() -> Result<(), Box>{ 7 | let mut x: Vec = Vec::new(); 8 | let mut y: Vec = Vec::new(); 9 | 10 | let mut reader = csv::Reader::from_reader(io::stdin()); 11 | for result in reader.records() { 12 | let record = result?; 13 | x.push(record[0].parse().unwrap()); 14 | y.push(record[1].parse().unwrap()); 15 | } 16 | 17 | let mut fg = Figure::new(); 18 | fg.axes2d() 19 | .set_title("Cat body measurements", &[]) 20 | .set_legend(Graph(0.9), Graph(0.1), &[], &[]) 21 | .set_x_label("height (cm)", &[]) 22 | .set_y_label("length (cm)", &[]) 23 | .points(x, y, &[Caption("Cat")]); 24 | fg.show(); 25 | Ok(()) 26 | } 27 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/src/bin/plot_results.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::io; 3 | use gnuplot::{Figure, Caption, Graph, Color, PointSymbol}; 4 | use gnuplot::AxesCommon; 5 | 6 | fn main() -> Result<(), Box>{ 7 | let mut x: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; 8 | let mut y: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; 9 | 10 | let mut reader = csv::Reader::from_reader(io::stdin()); 11 | for result in reader.records() { 12 | let record = result?; 13 | let class:usize = record[2].parse().unwrap(); 14 | x[class].push(record[0].parse().unwrap()); 15 | y[class].push(record[1].parse().unwrap()); 16 | } 17 | 18 | let mut fg = Figure::new(); 19 | fg.axes2d() 20 | .set_title("Cat breed classification result", &[]) 21 | .set_legend(Graph(0.9), Graph(0.1), &[], &[]) 22 | .set_x_label("height (cm)", &[]) 23 | .set_y_label("length (cm)", &[]) 24 | .points( 25 | &x[0], 26 | &y[0], 27 | &[Caption("Cat breed 1"), Color("red"), PointSymbol('+')], 28 | ) 29 | .points( 30 | &x[1], 31 | &y[1], 32 | &[Caption("Cat breed 2"), Color("green"), PointSymbol('x')], 33 | ) 34 | .points( 35 | &x[2], 36 | &y[2], 37 | &[Caption("Cat breed 3"), Color("blue"), PointSymbol('o')], 38 | ); 39 | fg.show(); 40 | Ok(()) 41 | } 42 | -------------------------------------------------------------------------------- /machine-learning/cat-breed-k-means/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /machine-learning/cat-or-dog-nnet/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "ansi_term" 5 | version = "0.11.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "atty" 13 | version = "0.2.13" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | dependencies = [ 16 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 17 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 18 | ] 19 | 20 | [[package]] 21 | name = "autocfg" 22 | version = "0.1.6" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | 25 | [[package]] 26 | name = "bitflags" 27 | version = "1.1.0" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | 30 | [[package]] 31 | name = "bstr" 32 | version = "0.2.8" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | dependencies = [ 35 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 36 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 37 | "regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 38 | "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", 39 | ] 40 | 41 | [[package]] 42 | name = "byteorder" 43 | version = "1.3.2" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | 46 | [[package]] 47 | name = "c2-chacha" 48 | version = "0.2.2" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | dependencies = [ 51 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 53 | ] 54 | 55 | [[package]] 56 | name = "cat-or-dog-nnet" 57 | version = "0.1.0" 58 | dependencies = [ 59 | "csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 60 | "gnuplot 0.0.31 (registry+https://github.com/rust-lang/crates.io-index)", 61 | "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 62 | "rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 63 | "rusty-machine 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", 64 | "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", 65 | "structopt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 66 | ] 67 | 68 | [[package]] 69 | name = "cfg-if" 70 | version = "0.1.9" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | 73 | [[package]] 74 | name = "clap" 75 | version = "2.33.0" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | dependencies = [ 78 | "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 79 | "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 82 | "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 85 | ] 86 | 87 | [[package]] 88 | name = "csv" 89 | version = "1.1.1" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | dependencies = [ 92 | "bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 93 | "csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 94 | "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 95 | "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 96 | "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", 97 | ] 98 | 99 | [[package]] 100 | name = "csv-core" 101 | version = "0.1.6" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | dependencies = [ 104 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 105 | ] 106 | 107 | [[package]] 108 | name = "fuchsia-cprng" 109 | version = "0.1.1" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | 112 | [[package]] 113 | name = "getrandom" 114 | version = "0.1.12" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | dependencies = [ 117 | "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 118 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 119 | "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 120 | ] 121 | 122 | [[package]] 123 | name = "gnuplot" 124 | version = "0.0.31" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | 127 | [[package]] 128 | name = "heck" 129 | version = "0.3.1" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | dependencies = [ 132 | "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 133 | ] 134 | 135 | [[package]] 136 | name = "itoa" 137 | version = "0.4.4" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | 140 | [[package]] 141 | name = "lazy_static" 142 | version = "1.4.0" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | 145 | [[package]] 146 | name = "libc" 147 | version = "0.2.62" 148 | source = "registry+https://github.com/rust-lang/crates.io-index" 149 | 150 | [[package]] 151 | name = "matrixmultiply" 152 | version = "0.1.15" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | dependencies = [ 155 | "rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 156 | ] 157 | 158 | [[package]] 159 | name = "memchr" 160 | version = "2.2.1" 161 | source = "registry+https://github.com/rust-lang/crates.io-index" 162 | dependencies = [ 163 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 164 | ] 165 | 166 | [[package]] 167 | name = "num" 168 | version = "0.1.42" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | dependencies = [ 171 | "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 172 | "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 173 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 174 | ] 175 | 176 | [[package]] 177 | name = "num-integer" 178 | version = "0.1.41" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | dependencies = [ 181 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 182 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 183 | ] 184 | 185 | [[package]] 186 | name = "num-iter" 187 | version = "0.1.39" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | dependencies = [ 190 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 191 | "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 192 | "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 193 | ] 194 | 195 | [[package]] 196 | name = "num-traits" 197 | version = "0.2.8" 198 | source = "registry+https://github.com/rust-lang/crates.io-index" 199 | dependencies = [ 200 | "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 201 | ] 202 | 203 | [[package]] 204 | name = "ppv-lite86" 205 | version = "0.2.5" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | 208 | [[package]] 209 | name = "proc-macro-error" 210 | version = "0.2.6" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | dependencies = [ 213 | "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 215 | "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 216 | ] 217 | 218 | [[package]] 219 | name = "proc-macro2" 220 | version = "1.0.3" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | dependencies = [ 223 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 224 | ] 225 | 226 | [[package]] 227 | name = "quote" 228 | version = "1.0.2" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | dependencies = [ 231 | "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 232 | ] 233 | 234 | [[package]] 235 | name = "rand" 236 | version = "0.3.23" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | dependencies = [ 239 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 240 | "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 241 | ] 242 | 243 | [[package]] 244 | name = "rand" 245 | version = "0.4.6" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | dependencies = [ 248 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 249 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 253 | ] 254 | 255 | [[package]] 256 | name = "rand" 257 | version = "0.7.0" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | dependencies = [ 260 | "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 261 | "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", 262 | "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 263 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 265 | ] 266 | 267 | [[package]] 268 | name = "rand_chacha" 269 | version = "0.2.1" 270 | source = "registry+https://github.com/rust-lang/crates.io-index" 271 | dependencies = [ 272 | "c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 273 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 274 | ] 275 | 276 | [[package]] 277 | name = "rand_core" 278 | version = "0.3.1" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | dependencies = [ 281 | "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 282 | ] 283 | 284 | [[package]] 285 | name = "rand_core" 286 | version = "0.4.2" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | 289 | [[package]] 290 | name = "rand_core" 291 | version = "0.5.1" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | dependencies = [ 294 | "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 295 | ] 296 | 297 | [[package]] 298 | name = "rand_distr" 299 | version = "0.2.2" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | dependencies = [ 302 | "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 303 | ] 304 | 305 | [[package]] 306 | name = "rand_hc" 307 | version = "0.2.0" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | dependencies = [ 310 | "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 311 | ] 312 | 313 | [[package]] 314 | name = "rawpointer" 315 | version = "0.1.0" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | 318 | [[package]] 319 | name = "rdrand" 320 | version = "0.4.0" 321 | source = "registry+https://github.com/rust-lang/crates.io-index" 322 | dependencies = [ 323 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 324 | ] 325 | 326 | [[package]] 327 | name = "regex-automata" 328 | version = "0.1.8" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | dependencies = [ 331 | "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 332 | ] 333 | 334 | [[package]] 335 | name = "rulinalg" 336 | version = "0.3.7" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | dependencies = [ 339 | "matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", 340 | "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 341 | ] 342 | 343 | [[package]] 344 | name = "rusty-machine" 345 | version = "0.5.4" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | dependencies = [ 348 | "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 349 | "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", 350 | "rulinalg 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 351 | ] 352 | 353 | [[package]] 354 | name = "ryu" 355 | version = "1.0.0" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | 358 | [[package]] 359 | name = "serde" 360 | version = "1.0.100" 361 | source = "registry+https://github.com/rust-lang/crates.io-index" 362 | dependencies = [ 363 | "serde_derive 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", 364 | ] 365 | 366 | [[package]] 367 | name = "serde_derive" 368 | version = "1.0.100" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | dependencies = [ 371 | "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 372 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 373 | "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 374 | ] 375 | 376 | [[package]] 377 | name = "strsim" 378 | version = "0.8.0" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | 381 | [[package]] 382 | name = "structopt" 383 | version = "0.3.1" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | dependencies = [ 386 | "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", 387 | "structopt-derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 388 | ] 389 | 390 | [[package]] 391 | name = "structopt-derive" 392 | version = "0.3.1" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | dependencies = [ 395 | "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 396 | "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 398 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 399 | "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 400 | ] 401 | 402 | [[package]] 403 | name = "syn" 404 | version = "1.0.5" 405 | source = "registry+https://github.com/rust-lang/crates.io-index" 406 | dependencies = [ 407 | "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 408 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 409 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 410 | ] 411 | 412 | [[package]] 413 | name = "textwrap" 414 | version = "0.11.0" 415 | source = "registry+https://github.com/rust-lang/crates.io-index" 416 | dependencies = [ 417 | "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 418 | ] 419 | 420 | [[package]] 421 | name = "unicode-segmentation" 422 | version = "1.3.0" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | 425 | [[package]] 426 | name = "unicode-width" 427 | version = "0.1.6" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | 430 | [[package]] 431 | name = "unicode-xid" 432 | version = "0.2.0" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | 435 | [[package]] 436 | name = "vec_map" 437 | version = "0.8.1" 438 | source = "registry+https://github.com/rust-lang/crates.io-index" 439 | 440 | [[package]] 441 | name = "wasi" 442 | version = "0.7.0" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | 445 | [[package]] 446 | name = "winapi" 447 | version = "0.3.8" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | dependencies = [ 450 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 451 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 452 | ] 453 | 454 | [[package]] 455 | name = "winapi-i686-pc-windows-gnu" 456 | version = "0.4.0" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | 459 | [[package]] 460 | name = "winapi-x86_64-pc-windows-gnu" 461 | version = "0.4.0" 462 | source = "registry+https://github.com/rust-lang/crates.io-index" 463 | 464 | [metadata] 465 | "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 466 | "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" 467 | "checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" 468 | "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" 469 | "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" 470 | "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 471 | "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" 472 | "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" 473 | "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" 474 | "checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" 475 | "checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c" 476 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 477 | "checksum getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571" 478 | "checksum gnuplot 0.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "18a907dc810202b800898a3059eba489404c7f232f8e141500122a86b173bd7f" 479 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 480 | "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" 481 | "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 482 | "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" 483 | "checksum matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "dcad67dcec2d58ff56f6292582377e6921afdf3bfbd533e26fb8900ae575e002" 484 | "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 485 | "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" 486 | "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" 487 | "checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e" 488 | "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" 489 | "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" 490 | "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" 491 | "checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8" 492 | "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" 493 | "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" 494 | "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" 495 | "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" 496 | "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" 497 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 498 | "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 499 | "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 500 | "checksum rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2" 501 | "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 502 | "checksum rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019" 503 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 504 | "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" 505 | "checksum rulinalg 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5670ce3717deb2d4436bdb29f07c549b56595f1fd8af1ca4682f1c1b1ac57f86" 506 | "checksum rusty-machine 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "dee5358236bbd0835aeee9a8b04c8b9b0aaea243a1a1a71253957b4606fb9171" 507 | "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" 508 | "checksum serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)" = "f4473e8506b213730ff2061073b48fa51dcc66349219e2e7c5608f0296a1d95a" 509 | "checksum serde_derive 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)" = "11e410fde43e157d789fc290d26bc940778ad0fdd47836426fbac36573710dbb" 510 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 511 | "checksum structopt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ac9d6e93dd792b217bf89cda5c14566e3043960c6f9da890c2ba5d09d07804c" 512 | "checksum structopt-derive 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ae9e5165d463a0dea76967d021f8d0f9316057bf5163aa2a4843790e842ff37" 513 | "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" 514 | "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 515 | "checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" 516 | "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" 517 | "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" 518 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" 519 | "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" 520 | "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 521 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 522 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 523 | -------------------------------------------------------------------------------- /machine-learning/cat-or-dog-nnet/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cat-or-dog-nnet" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rusty-machine = "0.5.4" 9 | csv = "1.1" 10 | rand = "0.7.0" 11 | rand_distr = "0.2.1" 12 | gnuplot = "0.0.31" 13 | structopt = "0.3.1" 14 | serde = { version = "1.0.100", features = ["derive"] } 15 | -------------------------------------------------------------------------------- /machine-learning/cat-or-dog-nnet/run.sh: -------------------------------------------------------------------------------- 1 | #cargo run --bin generate_data > training.csv 2 | #cargo run --bin generate_data > testing.csv 3 | 4 | cargo run --bin train_and_predict -- --train training.csv --test testing.csv 5 | -------------------------------------------------------------------------------- /machine-learning/cat-or-dog-nnet/src/bin/generate_data.rs: -------------------------------------------------------------------------------- 1 | extern crate rusty_machine; 2 | extern crate rand; 3 | 4 | use rusty_machine::linalg::{Matrix, BaseMatrix}; 5 | 6 | use rand::thread_rng; 7 | use rand::distributions::Distribution; // for using .sample() 8 | use rand_distr::Normal; // splitted from rand since 0.7 9 | use std::io; 10 | use serde::Serialize; 11 | 12 | // settings 13 | const CENTROIDS:[f64;4] = [ // Height, length 14 | 61.0, 99.5, // German Shepherd dog 15 | 22.5, 40.5, // Persian cat 16 | ]; 17 | 18 | const NOISE:f64 = 1.8; 19 | const SAMPLES_PER_CENTROID: usize = 2000; 20 | 21 | #[derive(Debug, Serialize)] 22 | struct Sample { 23 | height: f64, 24 | length: f64, 25 | category_id: usize 26 | } 27 | 28 | fn generate_data(centroids: &Matrix, 29 | points_per_centroid: usize, 30 | noise: f64) 31 | -> Vec { 32 | assert!(centroids.cols() > 0, "Centroids cannot be empty."); 33 | assert!(centroids.rows() > 0, "Centroids cannot be empty."); 34 | assert!(noise >= 0f64, "Noise must be non-negative."); 35 | let mut samples = Vec::with_capacity(points_per_centroid); 36 | 37 | let mut rng = thread_rng(); 38 | let normal_rv = Normal::new(0f64, noise).unwrap(); 39 | 40 | for _ in 0..points_per_centroid { 41 | // Generate points from each centroid 42 | for (centroid_id, centroid) in centroids.iter_rows().enumerate() { 43 | let mut point = Vec::with_capacity(centroids.cols()); 44 | for feature in centroid.iter() { 45 | point.push(feature + normal_rv.sample(&mut rng)); 46 | } 47 | 48 | samples.push(Sample { 49 | height: point[0], 50 | length: point[1], 51 | category_id: centroid_id, 52 | }); 53 | } 54 | } 55 | 56 | samples 57 | } 58 | 59 | fn main() -> Result<(), std::io::Error> { 60 | let centroids = Matrix::new(2, 2, CENTROIDS.to_vec()); 61 | 62 | let samples = generate_data(¢roids, SAMPLES_PER_CENTROID, NOISE); 63 | 64 | let mut writer = csv::Writer::from_writer(io::stdout()); 65 | // serialize will generate the column header automatically 66 | for sample in samples.iter() { 67 | writer.serialize(sample)?; 68 | } 69 | Ok(()) 70 | } 71 | -------------------------------------------------------------------------------- /machine-learning/cat-or-dog-nnet/src/bin/train_and_predict.rs: -------------------------------------------------------------------------------- 1 | extern crate rusty_machine; 2 | extern crate rand; 3 | 4 | use std::error::Error; 5 | use structopt::StructOpt; 6 | use serde::Deserialize; 7 | use csv; 8 | 9 | use rusty_machine::learning::nnet::{NeuralNet, BCECriterion}; 10 | use rusty_machine::learning::optim::grad_desc::StochasticGD; 11 | 12 | use rusty_machine::linalg::Matrix; 13 | use rusty_machine::learning::SupModel; 14 | use rusty_machine::data::transforms::{Transformer, Standardizer}; 15 | 16 | #[derive(StructOpt)] 17 | struct Options { 18 | #[structopt(short = "r", long = "train", parse(from_os_str))] 19 | /// Training data CSV file 20 | training_data_csv: std::path::PathBuf, 21 | 22 | #[structopt(short = "t", long = "test", parse(from_os_str))] 23 | /// Testing data CSV file 24 | testing_data_csv: std::path::PathBuf, 25 | } 26 | 27 | #[derive(Debug, Deserialize)] 28 | struct SampleRow { 29 | height: f64, 30 | length: f64, 31 | category_id: usize, 32 | } 33 | 34 | fn read_data_from_csv(file_path: std::path::PathBuf) 35 | -> Result<(Matrix, Matrix), Box> { 36 | let mut input_data = vec![]; 37 | let mut label_data = vec![]; 38 | let mut sample_count = 0; 39 | let mut reader = csv::Reader::from_path(file_path)?; 40 | for raw_row in reader.deserialize() { 41 | let row: SampleRow = raw_row?; 42 | input_data.push(row.height); 43 | input_data.push(row.length); 44 | label_data.push(row.category_id as f64); 45 | sample_count += 1 46 | } 47 | 48 | let inputs = Matrix::new(sample_count, 2, input_data); 49 | let targets = Matrix::new(sample_count, 1, label_data); 50 | return Ok((inputs, targets)) 51 | } 52 | 53 | 54 | fn main() -> Result<(), Box>{ 55 | 56 | let options = Options::from_args(); 57 | 58 | // load the data from CSV 59 | let (training_inputs, targets) = read_data_from_csv(options.training_data_csv).unwrap(); 60 | 61 | // Training ==================== 62 | // normalization 63 | let mut standardizer = Standardizer::new(0.0, 1.0); 64 | 65 | standardizer.fit(&training_inputs).unwrap(); 66 | let normalized_training_inputs = standardizer.transform(training_inputs).unwrap(); 67 | // println!("{:?}", normalized_training_inputs); 68 | 69 | let layers = &[2, 2, 1]; 70 | // http://www.deepideas.net/deep-learning-from-scratch-iii-training-criterion/ 71 | //let criterion = BCECriterion::new(Regularization::L2(0.)); 72 | //let criterion = BCECriterion::default(); 73 | // Create a multilayer perceptron with an input layer of size 2 and output layer of size 1 74 | // Uses a Sigmoid activation function and uses Stochastic gradient descent for training 75 | //let gradient_descent = StochasticGD::new(0.1, 0.1, 20); 76 | let mut model = NeuralNet::default(layers); 77 | 78 | model.train(&normalized_training_inputs, &targets).unwrap(); 79 | 80 | // Testing ==================== 81 | let (testing_inputs, expected) = read_data_from_csv(options.testing_data_csv).unwrap(); 82 | 83 | // Normalize the testing data using the mean and variance of the training data 84 | let normalized_test_cases = standardizer.transform(testing_inputs).unwrap(); 85 | // println!("{:?}", normalized_test_cases); 86 | 87 | let res = model.predict(&normalized_test_cases).unwrap(); 88 | 89 | // Calculating accuracy ================= 90 | println!("{:?}", res); 91 | 92 | println!("Evaluation..."); 93 | let mut hits = 0; 94 | let mut misses = 0; 95 | // Evaluation 96 | println!("Got\tExpected"); 97 | for (idx, prediction) in res.into_vec().iter().enumerate() { 98 | println!("{:.2}\t{}", prediction, expected[[idx, 0]]); 99 | if (prediction - 0.5) * (expected[[idx, 0]] - 0.5) > 0. { 100 | hits += 1; 101 | } else { 102 | misses += 1; 103 | } 104 | } 105 | 106 | println!("Hits: {}, Misses: {}", hits, misses); 107 | let hits_f = hits as f64; 108 | let total = (hits + misses) as f64; 109 | println!("Accuracy: {}%", (hits_f / total) * 100.); 110 | Ok(()) 111 | } 112 | 113 | -------------------------------------------------------------------------------- /physical/blink-cross-compile/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "blink-cross-compile" 5 | version = "0.1.0" 6 | dependencies = [ 7 | "rust_gpiozero 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 8 | ] 9 | 10 | [[package]] 11 | name = "lazy_static" 12 | version = "1.4.0" 13 | source = "registry+https://github.com/rust-lang/crates.io-index" 14 | 15 | [[package]] 16 | name = "libc" 17 | version = "0.2.66" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | 20 | [[package]] 21 | name = "rppal" 22 | version = "0.11.3" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | dependencies = [ 25 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 26 | "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 27 | ] 28 | 29 | [[package]] 30 | name = "rust_gpiozero" 31 | version = "0.2.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | dependencies = [ 34 | "rppal 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", 35 | ] 36 | 37 | [metadata] 38 | "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 39 | "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" 40 | "checksum rppal 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "137dbba1fb867daa27cda4c3cd6a11bca5bb5a1551f034cf9319b994846ddbe1" 41 | "checksum rust_gpiozero 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2de0e2fde7b1908026fcb13cff771d9cdb21d7e103220c3a6a9b62b4b8346fa8" 42 | -------------------------------------------------------------------------------- /physical/blink-cross-compile/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blink-cross-compile" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rust_gpiozero = "0.2.0" 9 | -------------------------------------------------------------------------------- /physical/blink-cross-compile/auto-blink: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/physical/blink-cross-compile/auto-blink -------------------------------------------------------------------------------- /physical/blink-cross-compile/button_debounce: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/physical/blink-cross-compile/button_debounce -------------------------------------------------------------------------------- /physical/blink-cross-compile/manual-blink: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/practical-rust-projects/6a422440986b085ba5756a990c9b3a46745f01a0/physical/blink-cross-compile/manual-blink -------------------------------------------------------------------------------- /physical/blink-cross-compile/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | 4 | fn main() { 5 | let mut led = LED::new(2); 6 | 7 | led.blink(1.0, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /physical/physical-computing/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "lazy_static" 5 | version = "1.4.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | 8 | [[package]] 9 | name = "libc" 10 | version = "0.2.66" 11 | source = "registry+https://github.com/rust-lang/crates.io-index" 12 | 13 | [[package]] 14 | name = "physical-computing" 15 | version = "0.1.0" 16 | dependencies = [ 17 | "rust_gpiozero 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 18 | ] 19 | 20 | [[package]] 21 | name = "rppal" 22 | version = "0.11.3" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | dependencies = [ 25 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 26 | "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 27 | ] 28 | 29 | [[package]] 30 | name = "rust_gpiozero" 31 | version = "0.2.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | dependencies = [ 34 | "rppal 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", 35 | ] 36 | 37 | [metadata] 38 | "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 39 | "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" 40 | "checksum rppal 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "137dbba1fb867daa27cda4c3cd6a11bca5bb5a1551f034cf9319b994846ddbe1" 41 | "checksum rust_gpiozero 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2de0e2fde7b1908026fcb13cff771d9cdb21d7e103220c3a6a9b62b4b8346fa8" 42 | -------------------------------------------------------------------------------- /physical/physical-computing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "physical-computing" 3 | version = "0.1.0" 4 | authors = ["Shing Lyu "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rust_gpiozero = "0.2.0" 9 | -------------------------------------------------------------------------------- /physical/physical-computing/examples/auto-blink.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | 4 | fn main() { 5 | let led = LED::new(2); 6 | 7 | led.blink(1.0, 1.0); 8 | led.wait(); 9 | } 10 | -------------------------------------------------------------------------------- /physical/physical-computing/examples/button-debounce.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | use std::time::{Duration, Instant}; 4 | 5 | fn main() { 6 | let mut led = LED::new(2); 7 | let mut button = Button::new(4); 8 | 9 | let mut last_clicked = Instant::now(); 10 | loop{ 11 | println!("wait for button"); 12 | button.wait_for_press(None); 13 | 14 | if last_clicked.elapsed() < Duration::new(1, 0) { 15 | continue 16 | } 17 | 18 | // Make the led switch on 19 | println!("button pressed!"); 20 | led.toggle(); 21 | last_clicked = Instant::now() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /physical/physical-computing/examples/button.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | 4 | fn main() { 5 | let mut led = LED::new(2); 6 | let mut button = Button::new(4); 7 | 8 | loop{ 9 | println!("wait for button"); 10 | button.wait_for_press(None); 11 | // Make the led switch on 12 | println!("button pressed!"); 13 | led.toggle(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /physical/physical-computing/examples/led-on.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | 4 | fn main() { 5 | let mut led = LED::new(2); 6 | 7 | led.on(); 8 | } 9 | -------------------------------------------------------------------------------- /physical/physical-computing/examples/manual-blink.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_gpiozero; 2 | use rust_gpiozero::*; 3 | use std::thread::sleep; 4 | use std::time::Duration; 5 | 6 | fn main() { 7 | let mut led = LED::new(2); 8 | 9 | loop{ 10 | println!("on"); 11 | led.on(); 12 | 13 | sleep(Duration::from_secs(1)); 14 | 15 | println!("off"); 16 | led.off(); 17 | 18 | sleep(Duration::from_secs(1)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /physical/physical-computing/sysfs.sh: -------------------------------------------------------------------------------- 1 | echo "2" > /sys/class/gpio/export 2 | echo "out" > /sys/class/gpio/gpio2/direction 3 | 4 | echo "0" > /sys/class/gpio/gpio2/value 5 | --------------------------------------------------------------------------------