├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── rustfmt.toml └── src ├── error.rs ├── main.rs ├── prelude.rs └── utils ├── direntry_froms.rs └── mod.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # By Default, Ignore any .*, except .gitignore 2 | .* 3 | !.gitignore 4 | 5 | # Allow vscode 6 | # !.vscode 7 | 8 | # By default 9 | _* 10 | 11 | # --- Rust 12 | target/ 13 | # '_' in src dir, ok. 14 | !src/**/_* 15 | 16 | 17 | # nodejs accept test 18 | !.mocharc.yaml 19 | 20 | # --- Safety net 21 | dist/ 22 | __pycache__/ 23 | node_modules/ 24 | npm-debug.log 25 | report.*.json 26 | 27 | *.parquet 28 | *.map 29 | *.zip 30 | *.gz 31 | *.tar 32 | *.tgz 33 | 34 | # videos 35 | *.mov 36 | *.mp4 37 | 38 | # images 39 | *.icns 40 | *.ico 41 | *.jpeg 42 | *.jpg 43 | *.png -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.66" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" 10 | 11 | [[package]] 12 | name = "autocfg" 13 | version = "1.1.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 16 | 17 | [[package]] 18 | name = "bitflags" 19 | version = "1.3.2" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 22 | 23 | [[package]] 24 | name = "bytes" 25 | version = "1.3.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" 28 | 29 | [[package]] 30 | name = "cfg-if" 31 | version = "1.0.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 34 | 35 | [[package]] 36 | name = "hermit-abi" 37 | version = "0.1.19" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 40 | dependencies = [ 41 | "libc", 42 | ] 43 | 44 | [[package]] 45 | name = "libc" 46 | version = "0.2.138" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" 49 | 50 | [[package]] 51 | name = "lock_api" 52 | version = "0.4.9" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" 55 | dependencies = [ 56 | "autocfg", 57 | "scopeguard", 58 | ] 59 | 60 | [[package]] 61 | name = "log" 62 | version = "0.4.17" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 65 | dependencies = [ 66 | "cfg-if", 67 | ] 68 | 69 | [[package]] 70 | name = "memchr" 71 | version = "2.5.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 74 | 75 | [[package]] 76 | name = "mio" 77 | version = "0.8.5" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" 80 | dependencies = [ 81 | "libc", 82 | "log", 83 | "wasi", 84 | "windows-sys", 85 | ] 86 | 87 | [[package]] 88 | name = "num_cpus" 89 | version = "1.14.0" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" 92 | dependencies = [ 93 | "hermit-abi", 94 | "libc", 95 | ] 96 | 97 | [[package]] 98 | name = "parking_lot" 99 | version = "0.12.1" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 102 | dependencies = [ 103 | "lock_api", 104 | "parking_lot_core", 105 | ] 106 | 107 | [[package]] 108 | name = "parking_lot_core" 109 | version = "0.9.5" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" 112 | dependencies = [ 113 | "cfg-if", 114 | "libc", 115 | "redox_syscall", 116 | "smallvec", 117 | "windows-sys", 118 | ] 119 | 120 | [[package]] 121 | name = "pin-project-lite" 122 | version = "0.2.9" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 125 | 126 | [[package]] 127 | name = "proc-macro2" 128 | version = "1.0.47" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 131 | dependencies = [ 132 | "unicode-ident", 133 | ] 134 | 135 | [[package]] 136 | name = "quote" 137 | version = "1.0.21" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 140 | dependencies = [ 141 | "proc-macro2", 142 | ] 143 | 144 | [[package]] 145 | name = "redox_syscall" 146 | version = "0.2.16" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 149 | dependencies = [ 150 | "bitflags", 151 | ] 152 | 153 | [[package]] 154 | name = "rust-base" 155 | version = "0.1.0" 156 | dependencies = [ 157 | "anyhow", 158 | "thiserror", 159 | "tokio", 160 | ] 161 | 162 | [[package]] 163 | name = "scopeguard" 164 | version = "1.1.0" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 167 | 168 | [[package]] 169 | name = "signal-hook-registry" 170 | version = "1.4.0" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" 173 | dependencies = [ 174 | "libc", 175 | ] 176 | 177 | [[package]] 178 | name = "smallvec" 179 | version = "1.10.0" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 182 | 183 | [[package]] 184 | name = "socket2" 185 | version = "0.4.7" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" 188 | dependencies = [ 189 | "libc", 190 | "winapi", 191 | ] 192 | 193 | [[package]] 194 | name = "syn" 195 | version = "1.0.105" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" 198 | dependencies = [ 199 | "proc-macro2", 200 | "quote", 201 | "unicode-ident", 202 | ] 203 | 204 | [[package]] 205 | name = "thiserror" 206 | version = "1.0.37" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" 209 | dependencies = [ 210 | "thiserror-impl", 211 | ] 212 | 213 | [[package]] 214 | name = "thiserror-impl" 215 | version = "1.0.37" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" 218 | dependencies = [ 219 | "proc-macro2", 220 | "quote", 221 | "syn", 222 | ] 223 | 224 | [[package]] 225 | name = "tokio" 226 | version = "1.23.0" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" 229 | dependencies = [ 230 | "autocfg", 231 | "bytes", 232 | "libc", 233 | "memchr", 234 | "mio", 235 | "num_cpus", 236 | "parking_lot", 237 | "pin-project-lite", 238 | "signal-hook-registry", 239 | "socket2", 240 | "tokio-macros", 241 | "windows-sys", 242 | ] 243 | 244 | [[package]] 245 | name = "tokio-macros" 246 | version = "1.8.2" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" 249 | dependencies = [ 250 | "proc-macro2", 251 | "quote", 252 | "syn", 253 | ] 254 | 255 | [[package]] 256 | name = "unicode-ident" 257 | version = "1.0.5" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 260 | 261 | [[package]] 262 | name = "wasi" 263 | version = "0.11.0+wasi-snapshot-preview1" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 266 | 267 | [[package]] 268 | name = "winapi" 269 | version = "0.3.9" 270 | source = "registry+https://github.com/rust-lang/crates.io-index" 271 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 272 | dependencies = [ 273 | "winapi-i686-pc-windows-gnu", 274 | "winapi-x86_64-pc-windows-gnu", 275 | ] 276 | 277 | [[package]] 278 | name = "winapi-i686-pc-windows-gnu" 279 | version = "0.4.0" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 282 | 283 | [[package]] 284 | name = "winapi-x86_64-pc-windows-gnu" 285 | version = "0.4.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 288 | 289 | [[package]] 290 | name = "windows-sys" 291 | version = "0.42.0" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 294 | dependencies = [ 295 | "windows_aarch64_gnullvm", 296 | "windows_aarch64_msvc", 297 | "windows_i686_gnu", 298 | "windows_i686_msvc", 299 | "windows_x86_64_gnu", 300 | "windows_x86_64_gnullvm", 301 | "windows_x86_64_msvc", 302 | ] 303 | 304 | [[package]] 305 | name = "windows_aarch64_gnullvm" 306 | version = "0.42.0" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 309 | 310 | [[package]] 311 | name = "windows_aarch64_msvc" 312 | version = "0.42.0" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 315 | 316 | [[package]] 317 | name = "windows_i686_gnu" 318 | version = "0.42.0" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 321 | 322 | [[package]] 323 | name = "windows_i686_msvc" 324 | version = "0.42.0" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 327 | 328 | [[package]] 329 | name = "windows_x86_64_gnu" 330 | version = "0.42.0" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 333 | 334 | [[package]] 335 | name = "windows_x86_64_gnullvm" 336 | version = "0.42.0" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 339 | 340 | [[package]] 341 | name = "windows_x86_64_msvc" 342 | version = "0.42.0" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 345 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-base" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | thiserror = "1" 8 | tokio = { version = "1", features = ["full"] } 9 | 10 | [dev-dependencies] 11 | anyhow = "1" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rust Programming Base Template for new Rust Application code. 2 | 3 | [YouTube Video](https://www.youtube.com/watch?v=oxx7MmN4Ib0&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q) 4 | 5 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # rustfmt doc - https://rust-lang.github.io/rustfmt/ 2 | 3 | hard_tabs = true 4 | edition = "2021" 5 | 6 | # For recording 7 | # max_width = 60 8 | # chain_width = 40 9 | # array_width = 40 -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | //! Main Crate Error 2 | 3 | #[derive(thiserror::Error, Debug)] 4 | pub enum Error { 5 | /// For starter, to remove as code matures. 6 | #[error("Generic error: {0}")] 7 | Generic(String), 8 | /// For starter, to remove as code matures. 9 | #[error("Static error: {0}")] 10 | Static(&'static str), 11 | 12 | #[error(transparent)] 13 | IO(#[from] std::io::Error), 14 | } 15 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | // #![allow(unused)] // For beginning only. 2 | 3 | use crate::prelude::*; 4 | use std::fs::read_dir; 5 | 6 | mod error; 7 | mod prelude; 8 | mod utils; 9 | 10 | fn main() -> Result<()> { 11 | println!("Hello, world!"); 12 | 13 | for entry in read_dir("./")?.filter_map(|e| e.ok()) { 14 | let entry: String = W(&entry).try_into()?; 15 | println!("{entry}"); 16 | } 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /src/prelude.rs: -------------------------------------------------------------------------------- 1 | //! Crate prelude 2 | 3 | // Re-export the crate Error. 4 | pub use crate::error::Error; 5 | 6 | // Alias Result to be the crate Result. 7 | pub type Result = core::result::Result; 8 | 9 | // Generic Wrapper tuple struct for newtype pattern, 10 | // mostly for external type to type From/TryFrom conversions 11 | pub struct W(pub T); 12 | 13 | // Personal preference. 14 | pub use std::format as f; 15 | -------------------------------------------------------------------------------- /src/utils/direntry_froms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use std::fs::DirEntry; 3 | 4 | impl TryFrom> for String { 5 | type Error = Error; 6 | fn try_from(val: W<&DirEntry>) -> Result { 7 | val.0 8 | .path() 9 | .to_str() 10 | .map(String::from) 11 | .ok_or_else(|| Error::Generic(f!("Invalid path {:?}", val.0))) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | mod direntry_froms; 2 | --------------------------------------------------------------------------------