File I/O
This page is under construction. Please come back later.
/****************************************************************************** * This program simply copies a file to the console character by * character like the Unix 'cat' program. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ifh); let mut c:i32 = 0; while getcodepoint(c,ifh) { putcodepoint(c); } close(ifh); } fn main() { if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ readTextFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO1.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:13:11
|
13 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:15:23
|
15 | while getcodepoint(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:18:8
|
18 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO1.rs:22:5
|
22 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO1.rs:24:3
|
24 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO1.rs:26:28
|
26 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO1.rs:13:2
|
13 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> FileIO1.rs:15:8
|
15 | while getcodepoint(c,ifh) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO1.rs:16:3
|
16 | putcodepoint(c);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO1.rs:18:2
|
18 | close(ifh);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO1.rs:12:35
|
12 | fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO1.rs:33:59
|
33 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 12 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ rustc FileIO1.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:13:11
|
13 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:15:23
|
15 | while getcodepoint(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO1.rs:18:8
|
18 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO1.rs:22:5
|
22 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO1.rs:24:3
|
24 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO1.rs:26:28
|
26 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO1.rs:13:2
|
13 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> FileIO1.rs:15:8
|
15 | while getcodepoint(c,ifh) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO1.rs:16:3
|
16 | putcodepoint(c);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO1.rs:18:2
|
18 | close(ifh);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO1.rs:12:35
|
12 | fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO1.rs:33:59
|
33 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 12 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
/****************************************************************************** * This program simply copies a file to the console line by line. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ifh); let mut line:&str = ""; while getline(line,ifh) { println!("{}", line); } close(ifh); } fn main() { if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ readTextFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO2.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:12:11
|
12 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:14:21
|
14 | while getline(line,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:17:8
|
17 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO2.rs:21:5
|
21 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO2.rs:23:3
|
23 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO2.rs:25:28
|
25 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO2.rs:12:2
|
12 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getline` in this scope
--> FileIO2.rs:14:8
|
14 | while getline(line,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO2.rs:17:2
|
17 | close(ifh);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO2.rs:11:35
|
11 | fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO2.rs:32:59
|
32 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ rustc FileIO2.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:12:11
|
12 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:14:21
|
14 | while getline(line,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO2.rs:17:8
|
17 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO2.rs:21:5
|
21 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO2.rs:23:3
|
23 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO2.rs:25:28
|
25 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO2.rs:12:2
|
12 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getline` in this scope
--> FileIO2.rs:14:8
|
14 | while getline(line,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO2.rs:17:2
|
17 | close(ifh);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO2.rs:11:35
|
11 | fn readTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO2.rs:32:59
|
32 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
/****************************************************************************** * This program reads bytes from a file and prints them in decimal format. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn readBinaryFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { binmode(ifh); let mut c:u8 = 0; let mut count:isize = 0; while getbyte(c,ifh) { print!("{} ", c); count += 1; if count % 20 == 0 { println!(""); } } if count % 20 != 0 { println!(""); } close(ifh)?; } fn main() { let args: Vec<String> = env::args().collect(); if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ readBinaryFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO3.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:13:10
|
13 | binmode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:16:18
|
16 | while getbyte(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:26:8
|
26 | close(ifh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO3.rs:33:3
|
33 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO3.rs:13:2
|
13 | binmode(ifh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `getbyte` in this scope
--> FileIO3.rs:16:8
|
16 | while getbyte(c,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO3.rs:26:2
|
26 | close(ifh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO3.rs:12:37
|
12 | fn readBinaryFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO3.rs:42:59
|
42 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ rustc FileIO3.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:13:10
|
13 | binmode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:16:18
|
16 | while getbyte(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO3.rs:26:8
|
26 | close(ifh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO3.rs:33:3
|
33 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO3.rs:13:2
|
13 | binmode(ifh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `getbyte` in this scope
--> FileIO3.rs:16:8
|
16 | while getbyte(c,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO3.rs:26:2
|
26 | close(ifh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO3.rs:12:37
|
12 | fn readBinaryFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO3.rs:42:59
|
42 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
/****************************************************************************** * This program simply writes characters from the alphabet to a file. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn writeTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ofh); // Latin alphabet { let mut c:i32 = 0x41; while c <= 0x5A { putcodepoint(c,ofh); c += 1; } } putchar('\n',ofh); // Greek alphabet { let mut c:i32 = 0x391; while c <= 0x3A9 { putcodepoint(c,ofh); c += 1; } } // Cyrillic alphabet { let mut c:i32 = 0x410; while c <= 0x42F { putcodepoint(c,ofh); c += 1; } } putchar('\n',ofh); // Katakana alphabet { let mut c:i32 = 0x30A0; while c <= 0x30FF { putcodepoint(c,ofh); c += 1; } } putchar('\n',ofh); close(ofh)?; } fn main() { if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ writeTextFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO4.rs
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:12:11
|
12 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:17:19
|
17 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:21:15
|
21 | putchar('\n',ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:26:19
|
26 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:34:19
|
34 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:38:15
|
38 | putchar('\n',ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:43:19
|
43 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:47:15
|
47 | putchar('\n',ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO4.rs:48:8
|
48 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO4.rs:52:5
|
52 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO4.rs:54:3
|
54 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO4.rs:56:28
|
56 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO4.rs:12:2
|
12 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO4.rs:17:4
|
17 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putchar` in this scope
--> FileIO4.rs:21:2
|
21 | putchar('\n',ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO4.rs:26:4
|
26 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO4.rs:34:4
|
34 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putchar` in this scope
--> FileIO4.rs:38:2
|
38 | putchar('\n',ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO4.rs:43:4
|
43 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putchar` in this scope
--> FileIO4.rs:47:2
|
47 | putchar('\n',ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO4.rs:48:2
|
48 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO4.rs:11:36
|
11 | fn writeTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO4.rs:63:59
|
63 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 23 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ cat output/testFileIO4.txt
cat: output/testFileIO4.txt: No such file or directory
/****************************************************************************** * This program simply writes lines with the alphabet to a file. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn writeTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ofh); printLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ofh); printLine("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",ofh); printLine("АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",ofh); printLine("゠ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタ",ofh); printLine("ダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ",ofh); printLine("ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ",ofh); close(ofh)?; } fn main() { if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ writeTextFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO5.rs
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:12:11
|
12 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:13:41
|
13 | printLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:14:39
|
14 | printLine("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:15:47
|
15 | printLine("АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:16:47
|
16 | printLine("゠ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:17:47
|
17 | printLine("ダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:18:47
|
18 | printLine("ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ",ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO5.rs:19:8
|
19 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO5.rs:23:5
|
23 | if args.len() != 2 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO5.rs:25:3
|
25 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO5.rs:27:28
|
27 | let mut filespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO5.rs:12:2
|
12 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:13:2
|
13 | printLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:14:2
|
14 | printLine("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:15:2
|
15 | printLine("АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:16:2
|
16 | printLine("゠ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:17:2
|
17 | printLine("ダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO5.rs:18:2
|
18 | printLine("ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ",ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO5.rs:19:2
|
19 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO5.rs:11:36
|
11 | fn writeTextFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO5.rs:34:59
|
34 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 21 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ cat output/testFileIO5.txt
cat: output/testFileIO5.txt: No such file or directory
/****************************************************************************** * This program simply writes the bytes 0 - 256 to a binary file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn writeBinaryFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> { binmode(ofh); { let mut b:isize = 0; while b <= 255 { putbyte(b,ofh); b += 1; } } close(ofh)?; } fn main() { let args: Vec<String> = env::args().collect(); if args.len() != 2 { println!("Syntax: {} {{filename}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut filespec:String = args[1]; match (|| -> Result<(), Arc<dyn error::Error>>{ writeBinaryFile(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO6.rs
error[E0425]: cannot find value `ofh` in this scope
--> FileIO6.rs:13:10
|
13 | binmode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO6.rs:17:14
|
17 | putbyte(b,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO6.rs:21:8
|
21 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO6.rs:28:3
|
28 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO6.rs:13:2
|
13 | binmode(ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putbyte` in this scope
--> FileIO6.rs:17:4
|
17 | putbyte(b,ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO6.rs:21:2
|
21 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO6.rs:12:38
|
12 | fn writeBinaryFile(filespec:&str) -> Result<(), Arc<dyn error::Error>> {
| --------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO6.rs:37:59
|
37 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ od -t x1 output/testFileIO6.bin
od: output/testFileIO6.bin: No such file or directory
/****************************************************************************** * This program simply copies one file to another, character by * character like the Unix 'cat' program. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ifh); utf8mode(ofh); let mut c:i32 = 0; while getcodepoint(c,ifh) { putcodepoint(c,ofh); } close(ifh); close(ofh)?; } fn main() { if args.len() != 3 { println!("Syntax: {} {{fromFilespec}} {{toFilespec}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut fromFilespec:String = args[1]; let mut toFilespec:String = args[2]; match (|| -> Result<(), Arc<dyn error::Error>>{ copyTextFile(&fromFilespec, &toFilespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO7.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:13:11
|
13 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:14:11
|
14 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:16:23
|
16 | while getcodepoint(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:17:18
|
17 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:19:8
|
19 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:20:8
|
20 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:24:5
|
24 | if args.len() != 3 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO7.rs:26:3
|
26 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:28:32
|
28 | let mut fromFilespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:29:30
|
29 | let mut toFilespec:String = args[2];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO7.rs:13:2
|
13 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO7.rs:14:2
|
14 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> FileIO7.rs:16:8
|
16 | while getcodepoint(c,ifh) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO7.rs:17:3
|
17 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO7.rs:19:2
|
19 | close(ifh);
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO7.rs:20:2
|
20 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO7.rs:12:56
|
12 | fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO7.rs:36:59
|
36 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 18 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/GettysburgAddress.txt output/testFileIO7.txt
diff: output/testFileIO7.txt: No such file or directory
$ rustc FileIO7.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:13:11
|
13 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:14:11
|
14 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:16:23
|
16 | while getcodepoint(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:17:18
|
17 | putcodepoint(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO7.rs:19:8
|
19 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO7.rs:20:8
|
20 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:24:5
|
24 | if args.len() != 3 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO7.rs:26:3
|
26 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:28:32
|
28 | let mut fromFilespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO7.rs:29:30
|
29 | let mut toFilespec:String = args[2];
| ^^^^ not found in this scope
|
help: consider importing this function
|
9 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO7.rs:13:2
|
13 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO7.rs:14:2
|
14 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getcodepoint` in this scope
--> FileIO7.rs:16:8
|
16 | while getcodepoint(c,ifh) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `putcodepoint` in this scope
--> FileIO7.rs:17:3
|
17 | putcodepoint(c,ofh);
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO7.rs:19:2
|
19 | close(ifh);
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO7.rs:20:2
|
20 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO7.rs:12:56
|
12 | fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO7.rs:36:59
|
36 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 18 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/UnicodeTest.utf8 output/testFileIO7.utf8
diff: output/testFileIO7.utf8: No such file or directory
/****************************************************************************** * This program simply copies one file to another, line by line. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> { utf8mode(ifh); utf8mode(ofh); let mut line:&str = ""; while getline(line,ifh) { printLine(line,ofh); } close(ifh); close(ofh)?; } fn main() { if args.len() != 3 { println!("Syntax: {} {{fromFilespec}} {{toFilespec}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut fromFilespec:String = args[1]; let mut toFilespec:String = args[2]; match (|| -> Result<(), Arc<dyn error::Error>>{ copyTextFile(&fromFilespec, &toFilespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO8.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:12:11
|
12 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:13:11
|
13 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:15:21
|
15 | while getline(line,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:16:18
|
16 | printLine(line,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:18:8
|
18 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:19:8
|
19 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:23:5
|
23 | if args.len() != 3 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO8.rs:25:3
|
25 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:27:32
|
27 | let mut fromFilespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:28:30
|
28 | let mut toFilespec:String = args[2];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO8.rs:12:2
|
12 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO8.rs:13:2
|
13 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getline` in this scope
--> FileIO8.rs:15:8
|
15 | while getline(line,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO8.rs:16:3
|
16 | printLine(line,ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO8.rs:18:2
|
18 | close(ifh);
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO8.rs:19:2
|
19 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO8.rs:11:56
|
11 | fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO8.rs:35:59
|
35 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 18 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/GettysburgAddress.txt output/testFileIO8.txt
diff: output/testFileIO8.txt: No such file or directory
$ rustc FileIO8.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:12:11
|
12 | utf8mode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:13:11
|
13 | utf8mode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:15:21
|
15 | while getline(line,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:16:18
|
16 | printLine(line,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO8.rs:18:8
|
18 | close(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO8.rs:19:8
|
19 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:23:5
|
23 | if args.len() != 3 {
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `exit` in this scope
--> FileIO8.rs:25:3
|
25 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:27:32
|
27 | let mut fromFilespec:String = args[1];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find value `args` in this scope
--> FileIO8.rs:28:30
|
28 | let mut toFilespec:String = args[2];
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::env::args;
|
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO8.rs:12:2
|
12 | utf8mode(ifh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `utf8mode` in this scope
--> FileIO8.rs:13:2
|
13 | utf8mode(ofh);
| ^^^^^^^^ not found in this scope
error[E0425]: cannot find function `getline` in this scope
--> FileIO8.rs:15:8
|
15 | while getline(line,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `printLine` in this scope
--> FileIO8.rs:16:3
|
16 | printLine(line,ofh);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO8.rs:18:2
|
18 | close(ifh);
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO8.rs:19:2
|
19 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO8.rs:11:56
|
11 | fn copyTextFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO8.rs:35:59
|
35 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 18 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/UnicodeTest.utf8 output/testFileIO8.utf8
diff: output/testFileIO8.utf8: No such file or directory
/****************************************************************************** * This program reads bytes from a binary file and copies them to another file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::env; use std::error; use std::sync::Arc; fn copyBinaryFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> { binmode(ifh); binmode(ofh); let mut c:u8 = 0; while getbyte(c,ifh) { putbyte(c,ofh); } close(ifh)?; close(ofh)?; } fn main() { let args: Vec<String> = env::args().collect(); if args.len() != 3 { println!("Syntax: {} {{fromFilespec}} {{toFilespec}}", utils::program_name().expect("program name should not be empty!")); exit(1); } let mut fromFilespec:String = args[1]; let mut toFilespec:String = args[2]; match (|| -> Result<(), Arc<dyn error::Error>>{ copyBinaryFile(&fromFilespec, &toFilespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){ println!("Error: {}", format!("{}", ex)); } } }; }
Output
$ rustc FileIO9.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:13:10
|
13 | binmode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:14:10
|
14 | binmode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:16:18
|
16 | while getbyte(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:17:13
|
17 | putbyte(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:19:8
|
19 | close(ifh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:20:8
|
20 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO9.rs:27:3
|
27 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:13:2
|
13 | binmode(ifh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:14:2
|
14 | binmode(ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `getbyte` in this scope
--> FileIO9.rs:16:8
|
16 | while getbyte(c,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putbyte` in this scope
--> FileIO9.rs:17:3
|
17 | putbyte(c,ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:19:2
|
19 | close(ifh)?;
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:20:2
|
20 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO9.rs:12:58
|
12 | fn copyBinaryFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO9.rs:37:59
|
37 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/GettysburgAddress.txt output/testFileIO9.txt
diff: output/testFileIO9.txt: No such file or directory
$ rustc FileIO9.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:13:10
|
13 | binmode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:14:10
|
14 | binmode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:16:18
|
16 | while getbyte(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:17:13
|
17 | putbyte(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:19:8
|
19 | close(ifh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:20:8
|
20 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO9.rs:27:3
|
27 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:13:2
|
13 | binmode(ifh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:14:2
|
14 | binmode(ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `getbyte` in this scope
--> FileIO9.rs:16:8
|
16 | while getbyte(c,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putbyte` in this scope
--> FileIO9.rs:17:3
|
17 | putbyte(c,ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:19:2
|
19 | close(ifh)?;
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:20:2
|
20 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO9.rs:12:58
|
12 | fn copyBinaryFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO9.rs:37:59
|
37 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/text/UnicodeTest.utf8 output/testFileIO9.utf8
diff: output/testFileIO9.utf8: No such file or directory
$ rustc FileIO9.rs
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:13:10
|
13 | binmode(ifh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:14:10
|
14 | binmode(ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:16:18
|
16 | while getbyte(c,ifh) {
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:17:13
|
17 | putbyte(c,ofh);
| ^^^ not found in this scope
error[E0425]: cannot find value `ifh` in this scope
--> FileIO9.rs:19:8
|
19 | close(ifh)?;
| ^^^ not found in this scope
error[E0425]: cannot find value `ofh` in this scope
--> FileIO9.rs:20:8
|
20 | close(ofh)?;
| ^^^ not found in this scope
error[E0425]: cannot find function `exit` in this scope
--> FileIO9.rs:27:3
|
27 | exit(1);
| ^^^^ not found in this scope
|
help: consider importing this function
|
8 + use std::process::exit;
|
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:13:2
|
13 | binmode(ifh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `binmode` in this scope
--> FileIO9.rs:14:2
|
14 | binmode(ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `getbyte` in this scope
--> FileIO9.rs:16:8
|
16 | while getbyte(c,ifh) {
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `putbyte` in this scope
--> FileIO9.rs:17:3
|
17 | putbyte(c,ofh);
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:19:2
|
19 | close(ifh)?;
| ^^^^^ not found in this scope
error[E0425]: cannot find function `close` in this scope
--> FileIO9.rs:20:2
|
20 | close(ofh)?;
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> FileIO9.rs:12:58
|
12 | fn copyBinaryFile(fromFilespec:&str, toFilespec:&str) -> Result<(), Arc<dyn error::Error>> {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Arc<dyn Error>>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>`
found unit type `()`
error[E0433]: failed to resolve: use of undeclared crate or module `io`
--> FileIO9.rs:37:59
|
37 | if let Some(ex) = utils::isCustomErrorType(ex.clone(), io::Error("".to_string())){
| ^^
| |
| use of undeclared crate or module `io`
| help: a builtin type with a similar name exists: `i8`
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0308, E0425, E0433.
For more information about an error, try `rustc --explain E0308`.
$ diff -q ../../data/images/GlowingCat.jpg output/testFileIO9.jpg
diff: output/testFileIO9.jpg: No such file or directory
Questions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- Base64 Decoding
- Base64 Encoding
- ChaCha20 Cipher
- Number of Primes
- One-Way Hash
- Palindrome Search
- Spell Checker
- XOR Cipher
References
- [[Rust Language Reference]]
- [[Rust Compiler]]