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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::fs::{File};
use std::io::{BufReader, self};
use std::process::{self};
fn read_text_file(filespec:&str) -> Result<(), utils::CustomError> {
let mut ifh:BufReader<File> = BufReader::new(File::open(filespec)?);
let mut c:Option<u32>;
c = utils::getcodepoint(&mut ifh);
while c != None {
utils::putcodepoint(&mut io::stdout(), c.unwrap());
c = utils::getcodepoint(&mut ifh);
}
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Syntax: FileIO1 {{filename}}");
process::exit(1);
}
let filespec:String = args[1].to_string();
match (|| -> Result<(), utils::CustomError>{
read_text_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
println!("Error: {}", format!("{}", ex));
}
_ => {
println!("Unexpected File Read Error");
}
}
}
};
}
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::fs::{File};
use std::io::{BufReader, BufRead};
use std::process::{self};
fn read_text_file(filespec:&str) -> Result<(), utils::CustomError> {
let mut ifh:BufReader<File> = utils::open_file_read(filespec)?;
let mut line:String = String::from("");
while ifh.read_line(&mut line).unwrap_or(0) != 0 {
line = String::from(line.trim_end().to_string());
println!("{}", line);
line.clear();
}
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Syntax: FileIO2 {{filename}}");
process::exit(1);
}
let filespec:String = args[1].to_string();
match (|| -> Result<(), utils::CustomError>{
read_text_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
println!("Error: {}", format!("{}", ex));
}
_ => {
println!("Unexpected File Read Error");
}
}
}
};
}
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 hexadecimal format.
*
* Copyright © 2021 Richard Lesh. All rights reserved.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::fs::{File};
use std::io::{BufReader};
use std::process::{self};
fn read_binary_file(filespec:&str) -> Result<(), utils::CustomError> {
let mut ifh:BufReader<File> = utils::open_file_read(filespec)?;
let mut c:Option<u8>;
let mut count:isize = 0;
c = utils::getbyte(&mut ifh);
while c != None {
print!("{0:02x} ", c.unwrap());
count += 1;
if count % 16 == 0 {
println!("");
}
c = utils::getbyte(&mut ifh);
}
if count % 16 != 0 {
println!("");
}
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Syntax: FileIO3 {{filename}}");
process::exit(1);
}
let filespec:String = args[1].to_string();
match (|| -> Result<(), utils::CustomError>{
read_binary_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
println!("Error: {}", format!("{}", ex));
}
_ => {
println!("Unexpected File Read Error");
}
}
}
};
}
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::fs::{File};
use std::io::{BufWriter, Write};
use std::process::{self};
fn write_text_file(filespec:&str) -> Result<(), utils::CustomError> {
let mut ofh:BufWriter<File> = BufWriter::new(File::create(filespec)?);
// Latin alphabet
{
let mut c:u32 = 0x41;
while c <= 0x5A {
utils::put_codepoint(&mut ofh, c);
c += 1;
}
}
write!(ofh, "{}", '\n')?;
// Greek alphabet
{
let mut c:u32 = 0x391;
while c <= 0x3A9 {
utils::put_codepoint(&mut ofh, c);
c += 1;
}
}
write!(ofh, "{}", '\n')?;
// Cyrillic alphabet
{
let mut c:u32 = 0x410;
while c <= 0x42F {
utils::put_codepoint(&mut ofh, c);
c += 1;
}
}
write!(ofh, "{}", '\n')?;
// Katakana alphabet
{
let mut c:u32 = 0x30A0;
while c <= 0x30FF {
utils::put_codepoint(&mut ofh, c);
c += 1;
}
}
write!(ofh, "{}", '\n')?;
ofh.flush()?;
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Syntax: FileIO4 {{filename}}");
process::exit(1);
}
let filespec:String = args[1].to_string();
match (|| -> Result<(), utils::CustomError>{
write_text_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
println!("Error: {}", format!("{}", ex));
}
_ => {
println!("Unexpected File Read Error");
}
}
}
};
}
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::process::{self};
fn write_text_file(filespec:&str) -> Result<(), utils::CustomError> {
printLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ofh.unwrap());
printLine("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",ofh.unwrap());
printLine("АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",ofh.unwrap());
printLine("゠ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタ",ofh.unwrap());
printLine("ダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ",ofh.unwrap());
printLine("ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ",ofh.unwrap());
return Ok(());
}
fn main() {
if args.len() != 2 {
println!("Syntax: FileIO5 {{filename}}");
process::exit(1);
}
let filespec:String = args[1].to_string();
match (|| -> Result<(), utils::CustomError>{
write_text_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
println!("Error: {}", format!("{}", ex));
}
_ => {
println!("Unexpected File Write Error");
}
}
}
};
}
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::process;
fn write_binary_file(filespec:&str) -> Result<(), utils::CustomError> {
{
let mut b:isize = 0;
while b <= 255 {
ofh.write(&[b])?;
b += 1;
}
}
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Syntax: FileIO6 {{filename}}");
process::exit(1);
}
let mut filespec:String = args[1];
match (|| -> Result<(), utils::CustomError>{
write_binary_file(&filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::process;
fn copy_text_file(from_filespec:&str, to_filespec:&str) -> Result<(), utils::CustomError> {
let mut c:u32;
while getcodepoint(c,ifh) {
putcodepoint(c,ofh);
}
return Ok(());
}
fn main() {
if args.len() != 3 {
println!("Syntax: FileIO7 {{fromFilespec}} {{toFilespec}}");
process::exit(1);
}
let mut from_filespec:String = args[1];
let mut to_filespec:String = args[2];
match (|| -> Result<(), utils::CustomError>{
copy_text_file(&from_filespec, &to_filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::process;
fn copy_text_file(from_filespec:&str, to_filespec:&str) -> Result<(), utils::CustomError> {
let mut line:String;
while ifh.read_line(&mut line).expect("Failed to read line") {
printLine(line,ofh);
}
return Ok(());
}
fn main() {
if args.len() != 3 {
println!("Syntax: FileIO8 {{fromFilespec}} {{toFilespec}}");
process::exit(1);
}
let mut from_filespec:String = args[1];
let mut to_filespec:String = args[2];
match (|| -> Result<(), utils::CustomError>{
copy_text_file(&from_filespec, &to_filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
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.
*****************************************************************************/
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#[macro_use]
mod utils;
use std::env;
use std::io::Read;
use std::process;
fn copy_binary_file(from_filespec:&str, to_filespec:&str) -> Result<(), utils::CustomError> {
let mut c:u8;
while (c = utils::getbyte(&mut ifh)) != -1 {
ofh.write(&[c])?;
}
return Ok(());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!("Syntax: FileIO9 {{fromFilespec}} {{toFilespec}}");
process::exit(1);
}
let mut from_filespec:String = args[1];
let mut to_filespec:String = args[2];
match (|| -> Result<(), utils::CustomError>{
copy_binary_file(&from_filespec, &to_filespec)?;
return Ok(());
})() {
Ok(()) => {},
Err(ex) => {
match ex {
utils::CustomError::IOError(ex) => {
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]]
Pure Programmer


