Pure Programmer
Blue Matrix


Cluster Map

Project: Huffman Coding

[[Huffman_coding|Huffman Coding]] is a particular type of code commonly used for lossless data compression. By using shorter codes for more common symbols in a file and longer codes for less common symbols, we can save space overall.

Write a program that reads in a file and writes out a shorter compressed file using a Huffman Code. You will need to process the file to compute the frequency counts for each symbol in the file before you construct the Huffman tree used to encode the file. You will also need to write out the Huffman tree at the beginning of the file so that it can be used to decompress the file.

The program should take three arguments on the command line: name of input file, name of output file, and C/D for compress or decompress.

Even though this is an "optimal" compression technique, it doesn't always result in a smaller file. Why is this? What is the worst case?

Output
$ rustc HuffmanCoding.rs error: struct fields are separated by `,` --> HuffmanCoding.rs:36:11 | 33 | struct Node { | ---- while parsing this struct ... 36 | left:Node; | ^ help: replace `;` with `,` error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:14:24 | 14 | fn putInt(i:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:21:15 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:42:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:43:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; 43 | self.frequency = f; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:44:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 44 | self.left = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:44:15 | 44 | self.left = NULL; | ^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:45:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 45 | self.right = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:45:16 | 45 | self.right = NULL; | ^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:47:15 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:48:10 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ----- this function doesn't have a `self` parameter 48 | putInt(self.value, ofh)?; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 47 | fn write(&self, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ++++++ error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:81:29 | 81 | fn writeTree(node:Node, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:89:17 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:102:23 | 102 | fn putBit(b:bool, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:115:25 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:130:28 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:187:10 | 187 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:189:18 | 189 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:195:8 | 195 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:199:10 | 199 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:200:21 | 200 | writeTree(tree[0], ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:202:10 | 202 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:204:18 | 204 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:205:14 | 205 | putCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:210:18 | 210 | putBit(false, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:214:8 | 214 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:215:8 | 215 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:219:10 | 219 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:221:10 | 221 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:223:23 | 223 | tree = vec![readTree(ifh)]; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:226:18 | 226 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:227:17 | 227 | lookupCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:229:8 | 229 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:230:8 | 230 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find function `exit` in this scope --> HuffmanCoding.rs:237:3 | 237 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | warning: unnecessary parentheses around `if` condition --> HuffmanCoding.rs:108:5 | 108 | if (partialBits == 8) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 108 - if (partialBits == 8) { 108 + if partialBits == 8 { | error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:15:2 | 15 | putbyte((i >> 8) & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:16:2 | 16 | putbyte(i & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:14:37 | 14 | fn putInt(i:isize, ofh:ofstream) -> 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[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:23:2 | 23 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:26:2 | 26 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:28:9 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ------------------------------------ expected `Result<isize, Arc<(dyn std::error::Error + 'static)>>` because of return type ... 28 | return i; | ^ expected `Result<isize, Arc<dyn Error>>`, found `isize` | = note: expected enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` found type `isize` help: try wrapping the expression in `Ok` | 28 | return Ok(i); | +++ + error[E0308]: mismatched types --> HuffmanCoding.rs:41:30 | 41 | fn new(v:isize, f:isize) -> Node { | --- ^^^^ expected `Node`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression error[E0308]: mismatched types --> HuffmanCoding.rs:47:28 | 47 | fn write(ofh:ofstream) -> 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[E0308]: mismatched types --> HuffmanCoding.rs:58:21 | 58 | let mut i:isize = list.len() - 2; | ----- ^^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 58 | let mut i:isize = (list.len() - 2).try_into().unwrap(); | + +++++++++++++++++++++ error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:14 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:34 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:59 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:80 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:105 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:121 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:65:28 | 65 | let temp:Node = list[j + 1]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:12 | 66 | list[j + 1] = list[j]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:26 | 66 | list[j + 1] = list[j]; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:67:12 | 67 | list[j] = temp; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0599]: no method named `write` found for struct `Node` in the current scope --> HuffmanCoding.rs:82:7 | 33 | struct Node { | ----------- method `write` not found for this struct ... 82 | node.write(ofh)?; | -----^^^^^----- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Node::write(node, ofh)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Node` --> HuffmanCoding.rs:47:2 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `write`, perhaps you need to implement one of them: candidate #1: `std::io::Write` candidate #2: `Hasher` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:84:18 | 84 | writeTree(node.left, ofh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:85:18 | 85 | writeTree(node.right, ofh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:83:22 | 83 | if node.value == -1 { | _________________________^ 84 | | writeTree(node.left, ofh)?; 85 | | writeTree(node.right, ofh)?; 86 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0308]: mismatched types --> HuffmanCoding.rs:91:19 | 91 | node = Node::new(getInt(ifh), 0)?; | --------- ^^^^^^^^^^^ expected `isize`, found `Result<isize, Arc<dyn Error>>` | | | arguments to this function are incorrect | = note: expected type `isize` found enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` note: associated function defined here --> HuffmanCoding.rs:41:5 | 41 | fn new(v:isize, f:isize) -> Node { | ^^^ ------- error[E0277]: the `?` operator can only be applied to values that implement `Try` --> HuffmanCoding.rs:91:9 | 91 | node = Node::new(getInt(ifh), 0)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Node` | = help: the trait `Try` is not implemented for `Node` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:93:8 | 93 | node.left = readTree(ifh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:94:8 | 94 | node.right = readTree(ifh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:96:9 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ----------------------------------- expected `Result<Node, Arc<dyn std::error::Error>>` because of return type ... 96 | return node; | ^^^^ expected `Result<Node, Arc<dyn Error>>`, found `Node` | = note: expected enum `Result<Node, Arc<dyn std::error::Error>>` found struct `Node` help: try wrapping the expression in `Ok` | 96 | return Ok(node); | +++ + error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:109:3 | 109 | putbyte(partialByte,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:108:24 | 108 | if (partialBits == 8) { | ___________________________^ 109 | | putbyte(partialByte,ofh); 110 | | partialByte = 0; 111 | | partialBits = 0; 112 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:116:10 | 116 | assert!(mapContains(huffmanCodes,c), "mapContains(huffmanCodes,c)"); | ^^^^^^^^^^^ not found in this scope error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:117:26 | 117 | let code = huffmanCodes.at(c); | ^^ method not found in `HashMap<i32, (isize, isize)>` error[E0308]: mismatched types --> HuffmanCoding.rs:121:3 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 121 | / while i_ < code.1 { 122 | | let b:bool = (code.0 & mask) != 0; 123 | | putBit(b, ofh)?; 124 | | mask >>= 1; 125 | | i_ += 1; 126 | | } | |_________^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:121:3 | 121 | while i_ < code.1 { | ^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on 122 | let b:bool = (code.0 & mask) != 0; 123 | putBit(b, ofh)?; | - if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 126 ~ } 127 ~ Ok(()) | error[E0069]: `return;` in a function whose return type is not `()` --> HuffmanCoding.rs:141:5 | 141 | return; | ^^^^^^ return type is not `()` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:145:17 | 145 | node = node.left; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:147:17 | 147 | node = node.right; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:153:3 | 153 | putbyte(node.value,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:134:2 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 134 | / while partialBits > 0 { 135 | | let mut mask:isize = 1 << (partialBits - 1); 136 | | let mut node:Node = tree[0]; 137 | | let mut outputPath:isize = 0; ... | 155 | | partialByte &= !(outputPath << partialBits); 156 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:134:2 | 134 | while partialBits > 0 { | ^^^^^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on ... 141 | return; | ------ if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 156 ~ } 157 ~ Ok(()) | error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:162:30 | 162 | constructHuffmanCodes(node.left, newCode); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:162:36 | 162 | constructHuffmanCodes(node.left, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 162 | constructHuffmanCodes(node.left, newCode.into()); | +++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:164:30 | 164 | constructHuffmanCodes(node.right, newCode); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:164:37 | 164 | constructHuffmanCodes(node.right, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 164 | constructHuffmanCodes(node.right, newCode.into()); | +++++++ error[E0308]: mismatched types --> HuffmanCoding.rs:166:16 | 166 | huffmanCodes[node.value] = code; | ^^^^^^^^^^ expected `&i32`, found `isize` error[E0433]: failed to resolve: use of undeclared type `Utils` --> HuffmanCoding.rs:171:11 | 171 | for k in Utils::keys(frequencies) { | ^^^^^ use of undeclared type `Utils` error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:172:38 | 172 | tree.push(Node::new(k, frequencies.at(k))); | ^^ method not found in `HashMap<isize, isize>` error[E0308]: mismatched types --> HuffmanCoding.rs:174:27 | 174 | let mut treeSize:isize = tree.len(); | ----- ^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 174 | let mut treeSize:isize = tree.len().try_into().unwrap(); | ++++++++++++++++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:178:11 | 178 | newNode.right = tree.pop().unwrap(); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:179:11 | 179 | newNode.left = tree.pop().unwrap(); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:180:31 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:180:56 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:182:14 | 174 | let mut treeSize:isize = tree.len(); | ----- expected due to this type ... 182 | treeSize = tree.len(); | ^^^^^^^^^^ expected `isize`, found `usize` error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:187:2 | 187 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:189:8 | 189 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:190:7 | 190 | if !mapContains(frequencies,(c) as isize) { | ^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:191:16 | 191 | frequencies[c] = 0; | ^ expected `&isize`, found `u8` error[E0308]: mismatched types --> HuffmanCoding.rs:193:15 | 193 | frequencies[c] += 1; | ^ expected `&isize`, found `u8` error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:195:2 | 195 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:186:45 | 186 | fn computeFrequencies(fromFilespec:&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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:199:2 | 199 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:202:2 | 202 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:204:8 | 204 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:205:11 | 205 | putCode(c, ofh)?; | ------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:115:4 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 205 | putCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:214:2 | 214 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:215:2 | 215 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:198:56 | 198 | fn compressFile(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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:219:2 | 219 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:221:2 | 221 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:223:14 | 223 | tree = vec![readTree(ifh)]; | ^^^^^^^^^^^^^ expected `Node`, found `Result<Node, Arc<dyn Error>>` | = note: expected struct `Node` found enum `Result<Node, Arc<(dyn std::error::Error + 'static)>>` error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:226:8 | 226 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:227:14 | 227 | lookupCode(c, ofh)?; | ---------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:130:4 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 227 | lookupCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:229:2 | 229 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:230:2 | 230 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:218:58 | 218 | fn decompressFile(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[E0308]: mismatched types --> HuffmanCoding.rs:248:35 | 248 | constructHuffmanCodes(tree[0], startCode); | --------------------- ^^^^^^^^^ expected `(isize, isize)`, found `[{integer}; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[{integer}; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[{integer}; 2]` into `(isize, isize)` | 248 | constructHuffmanCodes(tree[0], startCode.into()); | +++++++ error[E0433]: failed to resolve: use of undeclared crate or module `io` --> HuffmanCoding.rs:259:59 | 259 | 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 110 previous errors; 1 warning emitted Some errors have detailed explanations: E0069, E0277, E0308, E0412, E0424, E0425, E0433, E0599, E0609. For more information about an error, try `rustc --explain E0069`. $ rustc HuffmanCoding.rs error: struct fields are separated by `,` --> HuffmanCoding.rs:36:11 | 33 | struct Node { | ---- while parsing this struct ... 36 | left:Node; | ^ help: replace `;` with `,` error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:14:24 | 14 | fn putInt(i:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:21:15 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:42:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:43:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; 43 | self.frequency = f; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:44:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 44 | self.left = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:44:15 | 44 | self.left = NULL; | ^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:45:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 45 | self.right = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:45:16 | 45 | self.right = NULL; | ^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:47:15 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:48:10 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ----- this function doesn't have a `self` parameter 48 | putInt(self.value, ofh)?; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 47 | fn write(&self, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ++++++ error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:81:29 | 81 | fn writeTree(node:Node, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:89:17 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:102:23 | 102 | fn putBit(b:bool, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:115:25 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:130:28 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:187:10 | 187 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:189:18 | 189 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:195:8 | 195 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:199:10 | 199 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:200:21 | 200 | writeTree(tree[0], ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:202:10 | 202 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:204:18 | 204 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:205:14 | 205 | putCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:210:18 | 210 | putBit(false, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:214:8 | 214 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:215:8 | 215 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:219:10 | 219 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:221:10 | 221 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:223:23 | 223 | tree = vec![readTree(ifh)]; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:226:18 | 226 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:227:17 | 227 | lookupCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:229:8 | 229 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:230:8 | 230 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find function `exit` in this scope --> HuffmanCoding.rs:237:3 | 237 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | warning: unnecessary parentheses around `if` condition --> HuffmanCoding.rs:108:5 | 108 | if (partialBits == 8) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 108 - if (partialBits == 8) { 108 + if partialBits == 8 { | error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:15:2 | 15 | putbyte((i >> 8) & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:16:2 | 16 | putbyte(i & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:14:37 | 14 | fn putInt(i:isize, ofh:ofstream) -> 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[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:23:2 | 23 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:26:2 | 26 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:28:9 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ------------------------------------ expected `Result<isize, Arc<(dyn std::error::Error + 'static)>>` because of return type ... 28 | return i; | ^ expected `Result<isize, Arc<dyn Error>>`, found `isize` | = note: expected enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` found type `isize` help: try wrapping the expression in `Ok` | 28 | return Ok(i); | +++ + error[E0308]: mismatched types --> HuffmanCoding.rs:41:30 | 41 | fn new(v:isize, f:isize) -> Node { | --- ^^^^ expected `Node`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression error[E0308]: mismatched types --> HuffmanCoding.rs:47:28 | 47 | fn write(ofh:ofstream) -> 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[E0308]: mismatched types --> HuffmanCoding.rs:58:21 | 58 | let mut i:isize = list.len() - 2; | ----- ^^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 58 | let mut i:isize = (list.len() - 2).try_into().unwrap(); | + +++++++++++++++++++++ error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:14 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:34 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:59 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:80 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:105 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:121 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:65:28 | 65 | let temp:Node = list[j + 1]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:12 | 66 | list[j + 1] = list[j]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:26 | 66 | list[j + 1] = list[j]; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:67:12 | 67 | list[j] = temp; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0599]: no method named `write` found for struct `Node` in the current scope --> HuffmanCoding.rs:82:7 | 33 | struct Node { | ----------- method `write` not found for this struct ... 82 | node.write(ofh)?; | -----^^^^^----- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Node::write(node, ofh)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Node` --> HuffmanCoding.rs:47:2 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `write`, perhaps you need to implement one of them: candidate #1: `std::io::Write` candidate #2: `Hasher` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:84:18 | 84 | writeTree(node.left, ofh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:85:18 | 85 | writeTree(node.right, ofh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:83:22 | 83 | if node.value == -1 { | _________________________^ 84 | | writeTree(node.left, ofh)?; 85 | | writeTree(node.right, ofh)?; 86 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0308]: mismatched types --> HuffmanCoding.rs:91:19 | 91 | node = Node::new(getInt(ifh), 0)?; | --------- ^^^^^^^^^^^ expected `isize`, found `Result<isize, Arc<dyn Error>>` | | | arguments to this function are incorrect | = note: expected type `isize` found enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` note: associated function defined here --> HuffmanCoding.rs:41:5 | 41 | fn new(v:isize, f:isize) -> Node { | ^^^ ------- error[E0277]: the `?` operator can only be applied to values that implement `Try` --> HuffmanCoding.rs:91:9 | 91 | node = Node::new(getInt(ifh), 0)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Node` | = help: the trait `Try` is not implemented for `Node` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:93:8 | 93 | node.left = readTree(ifh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:94:8 | 94 | node.right = readTree(ifh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:96:9 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ----------------------------------- expected `Result<Node, Arc<dyn std::error::Error>>` because of return type ... 96 | return node; | ^^^^ expected `Result<Node, Arc<dyn Error>>`, found `Node` | = note: expected enum `Result<Node, Arc<dyn std::error::Error>>` found struct `Node` help: try wrapping the expression in `Ok` | 96 | return Ok(node); | +++ + error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:109:3 | 109 | putbyte(partialByte,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:108:24 | 108 | if (partialBits == 8) { | ___________________________^ 109 | | putbyte(partialByte,ofh); 110 | | partialByte = 0; 111 | | partialBits = 0; 112 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:116:10 | 116 | assert!(mapContains(huffmanCodes,c), "mapContains(huffmanCodes,c)"); | ^^^^^^^^^^^ not found in this scope error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:117:26 | 117 | let code = huffmanCodes.at(c); | ^^ method not found in `HashMap<i32, (isize, isize)>` error[E0308]: mismatched types --> HuffmanCoding.rs:121:3 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 121 | / while i_ < code.1 { 122 | | let b:bool = (code.0 & mask) != 0; 123 | | putBit(b, ofh)?; 124 | | mask >>= 1; 125 | | i_ += 1; 126 | | } | |_________^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:121:3 | 121 | while i_ < code.1 { | ^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on 122 | let b:bool = (code.0 & mask) != 0; 123 | putBit(b, ofh)?; | - if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 126 ~ } 127 ~ Ok(()) | error[E0069]: `return;` in a function whose return type is not `()` --> HuffmanCoding.rs:141:5 | 141 | return; | ^^^^^^ return type is not `()` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:145:17 | 145 | node = node.left; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:147:17 | 147 | node = node.right; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:153:3 | 153 | putbyte(node.value,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:134:2 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 134 | / while partialBits > 0 { 135 | | let mut mask:isize = 1 << (partialBits - 1); 136 | | let mut node:Node = tree[0]; 137 | | let mut outputPath:isize = 0; ... | 155 | | partialByte &= !(outputPath << partialBits); 156 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:134:2 | 134 | while partialBits > 0 { | ^^^^^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on ... 141 | return; | ------ if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 156 ~ } 157 ~ Ok(()) | error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:162:30 | 162 | constructHuffmanCodes(node.left, newCode); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:162:36 | 162 | constructHuffmanCodes(node.left, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 162 | constructHuffmanCodes(node.left, newCode.into()); | +++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:164:30 | 164 | constructHuffmanCodes(node.right, newCode); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:164:37 | 164 | constructHuffmanCodes(node.right, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 164 | constructHuffmanCodes(node.right, newCode.into()); | +++++++ error[E0308]: mismatched types --> HuffmanCoding.rs:166:16 | 166 | huffmanCodes[node.value] = code; | ^^^^^^^^^^ expected `&i32`, found `isize` error[E0433]: failed to resolve: use of undeclared type `Utils` --> HuffmanCoding.rs:171:11 | 171 | for k in Utils::keys(frequencies) { | ^^^^^ use of undeclared type `Utils` error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:172:38 | 172 | tree.push(Node::new(k, frequencies.at(k))); | ^^ method not found in `HashMap<isize, isize>` error[E0308]: mismatched types --> HuffmanCoding.rs:174:27 | 174 | let mut treeSize:isize = tree.len(); | ----- ^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 174 | let mut treeSize:isize = tree.len().try_into().unwrap(); | ++++++++++++++++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:178:11 | 178 | newNode.right = tree.pop().unwrap(); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:179:11 | 179 | newNode.left = tree.pop().unwrap(); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:180:31 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:180:56 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:182:14 | 174 | let mut treeSize:isize = tree.len(); | ----- expected due to this type ... 182 | treeSize = tree.len(); | ^^^^^^^^^^ expected `isize`, found `usize` error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:187:2 | 187 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:189:8 | 189 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:190:7 | 190 | if !mapContains(frequencies,(c) as isize) { | ^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:191:16 | 191 | frequencies[c] = 0; | ^ expected `&isize`, found `u8` error[E0308]: mismatched types --> HuffmanCoding.rs:193:15 | 193 | frequencies[c] += 1; | ^ expected `&isize`, found `u8` error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:195:2 | 195 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:186:45 | 186 | fn computeFrequencies(fromFilespec:&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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:199:2 | 199 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:202:2 | 202 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:204:8 | 204 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:205:11 | 205 | putCode(c, ofh)?; | ------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:115:4 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 205 | putCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:214:2 | 214 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:215:2 | 215 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:198:56 | 198 | fn compressFile(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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:219:2 | 219 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:221:2 | 221 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:223:14 | 223 | tree = vec![readTree(ifh)]; | ^^^^^^^^^^^^^ expected `Node`, found `Result<Node, Arc<dyn Error>>` | = note: expected struct `Node` found enum `Result<Node, Arc<(dyn std::error::Error + 'static)>>` error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:226:8 | 226 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:227:14 | 227 | lookupCode(c, ofh)?; | ---------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:130:4 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 227 | lookupCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:229:2 | 229 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:230:2 | 230 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:218:58 | 218 | fn decompressFile(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[E0308]: mismatched types --> HuffmanCoding.rs:248:35 | 248 | constructHuffmanCodes(tree[0], startCode); | --------------------- ^^^^^^^^^ expected `(isize, isize)`, found `[{integer}; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[{integer}; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[{integer}; 2]` into `(isize, isize)` | 248 | constructHuffmanCodes(tree[0], startCode.into()); | +++++++ error[E0433]: failed to resolve: use of undeclared crate or module `io` --> HuffmanCoding.rs:259:59 | 259 | 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 110 previous errors; 1 warning emitted Some errors have detailed explanations: E0069, E0277, E0308, E0412, E0424, E0425, E0433, E0599, E0609. For more information about an error, try `rustc --explain E0069`. $ ls -al output/testUnicodeTest.* ls: output/testUnicodeTest.*: No such file or directory $ diff ../../data/text/UnicodeTest.utf8 output/testUnicodeTest.txt diff: output/testUnicodeTest.txt: No such file or directory $ rustc HuffmanCoding.rs error: struct fields are separated by `,` --> HuffmanCoding.rs:36:11 | 33 | struct Node { | ---- while parsing this struct ... 36 | left:Node; | ^ help: replace `;` with `,` error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:14:24 | 14 | fn putInt(i:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:21:15 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:42:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:43:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; 43 | self.frequency = f; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:44:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 44 | self.left = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:44:15 | 44 | self.left = NULL; | ^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:45:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 45 | self.right = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:45:16 | 45 | self.right = NULL; | ^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:47:15 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:48:10 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ----- this function doesn't have a `self` parameter 48 | putInt(self.value, ofh)?; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 47 | fn write(&self, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ++++++ error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:81:29 | 81 | fn writeTree(node:Node, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:89:17 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:102:23 | 102 | fn putBit(b:bool, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:115:25 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:130:28 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:187:10 | 187 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:189:18 | 189 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:195:8 | 195 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:199:10 | 199 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:200:21 | 200 | writeTree(tree[0], ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:202:10 | 202 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:204:18 | 204 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:205:14 | 205 | putCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:210:18 | 210 | putBit(false, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:214:8 | 214 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:215:8 | 215 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:219:10 | 219 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:221:10 | 221 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:223:23 | 223 | tree = vec![readTree(ifh)]; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:226:18 | 226 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:227:17 | 227 | lookupCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:229:8 | 229 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:230:8 | 230 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find function `exit` in this scope --> HuffmanCoding.rs:237:3 | 237 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | warning: unnecessary parentheses around `if` condition --> HuffmanCoding.rs:108:5 | 108 | if (partialBits == 8) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 108 - if (partialBits == 8) { 108 + if partialBits == 8 { | error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:15:2 | 15 | putbyte((i >> 8) & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:16:2 | 16 | putbyte(i & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:14:37 | 14 | fn putInt(i:isize, ofh:ofstream) -> 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[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:23:2 | 23 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:26:2 | 26 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:28:9 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ------------------------------------ expected `Result<isize, Arc<(dyn std::error::Error + 'static)>>` because of return type ... 28 | return i; | ^ expected `Result<isize, Arc<dyn Error>>`, found `isize` | = note: expected enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` found type `isize` help: try wrapping the expression in `Ok` | 28 | return Ok(i); | +++ + error[E0308]: mismatched types --> HuffmanCoding.rs:41:30 | 41 | fn new(v:isize, f:isize) -> Node { | --- ^^^^ expected `Node`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression error[E0308]: mismatched types --> HuffmanCoding.rs:47:28 | 47 | fn write(ofh:ofstream) -> 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[E0308]: mismatched types --> HuffmanCoding.rs:58:21 | 58 | let mut i:isize = list.len() - 2; | ----- ^^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 58 | let mut i:isize = (list.len() - 2).try_into().unwrap(); | + +++++++++++++++++++++ error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:14 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:34 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:59 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:80 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:105 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:121 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:65:28 | 65 | let temp:Node = list[j + 1]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:12 | 66 | list[j + 1] = list[j]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:26 | 66 | list[j + 1] = list[j]; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:67:12 | 67 | list[j] = temp; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0599]: no method named `write` found for struct `Node` in the current scope --> HuffmanCoding.rs:82:7 | 33 | struct Node { | ----------- method `write` not found for this struct ... 82 | node.write(ofh)?; | -----^^^^^----- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Node::write(node, ofh)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Node` --> HuffmanCoding.rs:47:2 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `write`, perhaps you need to implement one of them: candidate #1: `std::io::Write` candidate #2: `Hasher` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:84:18 | 84 | writeTree(node.left, ofh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:85:18 | 85 | writeTree(node.right, ofh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:83:22 | 83 | if node.value == -1 { | _________________________^ 84 | | writeTree(node.left, ofh)?; 85 | | writeTree(node.right, ofh)?; 86 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0308]: mismatched types --> HuffmanCoding.rs:91:19 | 91 | node = Node::new(getInt(ifh), 0)?; | --------- ^^^^^^^^^^^ expected `isize`, found `Result<isize, Arc<dyn Error>>` | | | arguments to this function are incorrect | = note: expected type `isize` found enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` note: associated function defined here --> HuffmanCoding.rs:41:5 | 41 | fn new(v:isize, f:isize) -> Node { | ^^^ ------- error[E0277]: the `?` operator can only be applied to values that implement `Try` --> HuffmanCoding.rs:91:9 | 91 | node = Node::new(getInt(ifh), 0)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Node` | = help: the trait `Try` is not implemented for `Node` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:93:8 | 93 | node.left = readTree(ifh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:94:8 | 94 | node.right = readTree(ifh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:96:9 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ----------------------------------- expected `Result<Node, Arc<dyn std::error::Error>>` because of return type ... 96 | return node; | ^^^^ expected `Result<Node, Arc<dyn Error>>`, found `Node` | = note: expected enum `Result<Node, Arc<dyn std::error::Error>>` found struct `Node` help: try wrapping the expression in `Ok` | 96 | return Ok(node); | +++ + error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:109:3 | 109 | putbyte(partialByte,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:108:24 | 108 | if (partialBits == 8) { | ___________________________^ 109 | | putbyte(partialByte,ofh); 110 | | partialByte = 0; 111 | | partialBits = 0; 112 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:116:10 | 116 | assert!(mapContains(huffmanCodes,c), "mapContains(huffmanCodes,c)"); | ^^^^^^^^^^^ not found in this scope error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:117:26 | 117 | let code = huffmanCodes.at(c); | ^^ method not found in `HashMap<i32, (isize, isize)>` error[E0308]: mismatched types --> HuffmanCoding.rs:121:3 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 121 | / while i_ < code.1 { 122 | | let b:bool = (code.0 & mask) != 0; 123 | | putBit(b, ofh)?; 124 | | mask >>= 1; 125 | | i_ += 1; 126 | | } | |_________^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:121:3 | 121 | while i_ < code.1 { | ^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on 122 | let b:bool = (code.0 & mask) != 0; 123 | putBit(b, ofh)?; | - if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 126 ~ } 127 ~ Ok(()) | error[E0069]: `return;` in a function whose return type is not `()` --> HuffmanCoding.rs:141:5 | 141 | return; | ^^^^^^ return type is not `()` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:145:17 | 145 | node = node.left; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:147:17 | 147 | node = node.right; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:153:3 | 153 | putbyte(node.value,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:134:2 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 134 | / while partialBits > 0 { 135 | | let mut mask:isize = 1 << (partialBits - 1); 136 | | let mut node:Node = tree[0]; 137 | | let mut outputPath:isize = 0; ... | 155 | | partialByte &= !(outputPath << partialBits); 156 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:134:2 | 134 | while partialBits > 0 { | ^^^^^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on ... 141 | return; | ------ if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 156 ~ } 157 ~ Ok(()) | error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:162:30 | 162 | constructHuffmanCodes(node.left, newCode); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:162:36 | 162 | constructHuffmanCodes(node.left, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 162 | constructHuffmanCodes(node.left, newCode.into()); | +++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:164:30 | 164 | constructHuffmanCodes(node.right, newCode); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:164:37 | 164 | constructHuffmanCodes(node.right, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 164 | constructHuffmanCodes(node.right, newCode.into()); | +++++++ error[E0308]: mismatched types --> HuffmanCoding.rs:166:16 | 166 | huffmanCodes[node.value] = code; | ^^^^^^^^^^ expected `&i32`, found `isize` error[E0433]: failed to resolve: use of undeclared type `Utils` --> HuffmanCoding.rs:171:11 | 171 | for k in Utils::keys(frequencies) { | ^^^^^ use of undeclared type `Utils` error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:172:38 | 172 | tree.push(Node::new(k, frequencies.at(k))); | ^^ method not found in `HashMap<isize, isize>` error[E0308]: mismatched types --> HuffmanCoding.rs:174:27 | 174 | let mut treeSize:isize = tree.len(); | ----- ^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 174 | let mut treeSize:isize = tree.len().try_into().unwrap(); | ++++++++++++++++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:178:11 | 178 | newNode.right = tree.pop().unwrap(); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:179:11 | 179 | newNode.left = tree.pop().unwrap(); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:180:31 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:180:56 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:182:14 | 174 | let mut treeSize:isize = tree.len(); | ----- expected due to this type ... 182 | treeSize = tree.len(); | ^^^^^^^^^^ expected `isize`, found `usize` error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:187:2 | 187 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:189:8 | 189 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:190:7 | 190 | if !mapContains(frequencies,(c) as isize) { | ^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:191:16 | 191 | frequencies[c] = 0; | ^ expected `&isize`, found `u8` error[E0308]: mismatched types --> HuffmanCoding.rs:193:15 | 193 | frequencies[c] += 1; | ^ expected `&isize`, found `u8` error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:195:2 | 195 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:186:45 | 186 | fn computeFrequencies(fromFilespec:&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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:199:2 | 199 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:202:2 | 202 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:204:8 | 204 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:205:11 | 205 | putCode(c, ofh)?; | ------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:115:4 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 205 | putCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:214:2 | 214 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:215:2 | 215 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:198:56 | 198 | fn compressFile(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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:219:2 | 219 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:221:2 | 221 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:223:14 | 223 | tree = vec![readTree(ifh)]; | ^^^^^^^^^^^^^ expected `Node`, found `Result<Node, Arc<dyn Error>>` | = note: expected struct `Node` found enum `Result<Node, Arc<(dyn std::error::Error + 'static)>>` error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:226:8 | 226 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:227:14 | 227 | lookupCode(c, ofh)?; | ---------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:130:4 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 227 | lookupCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:229:2 | 229 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:230:2 | 230 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:218:58 | 218 | fn decompressFile(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[E0308]: mismatched types --> HuffmanCoding.rs:248:35 | 248 | constructHuffmanCodes(tree[0], startCode); | --------------------- ^^^^^^^^^ expected `(isize, isize)`, found `[{integer}; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[{integer}; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[{integer}; 2]` into `(isize, isize)` | 248 | constructHuffmanCodes(tree[0], startCode.into()); | +++++++ error[E0433]: failed to resolve: use of undeclared crate or module `io` --> HuffmanCoding.rs:259:59 | 259 | 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 110 previous errors; 1 warning emitted Some errors have detailed explanations: E0069, E0277, E0308, E0412, E0424, E0425, E0433, E0599, E0609. For more information about an error, try `rustc --explain E0069`. $ rustc HuffmanCoding.rs error: struct fields are separated by `,` --> HuffmanCoding.rs:36:11 | 33 | struct Node { | ---- while parsing this struct ... 36 | left:Node; | ^ help: replace `;` with `,` error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:14:24 | 14 | fn putInt(i:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:21:15 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:42:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:43:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter 42 | self.value = v; 43 | self.frequency = f; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:44:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 44 | self.left = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:44:15 | 44 | self.left = NULL; | ^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:45:3 | 41 | fn new(v:isize, f:isize) -> Node { | --- this function doesn't have a `self` parameter ... 45 | self.right = NULL; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 41 | fn new(&self, v:isize, f:isize) -> Node { | ++++++ error[E0425]: cannot find value `NULL` in this scope --> HuffmanCoding.rs:45:16 | 45 | self.right = NULL; | ^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:47:15 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0424]: expected value, found module `self` --> HuffmanCoding.rs:48:10 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ----- this function doesn't have a `self` parameter 48 | putInt(self.value, ofh)?; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 47 | fn write(&self, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ++++++ error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:81:29 | 81 | fn writeTree(node:Node, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ifstream` in this scope --> HuffmanCoding.rs:89:17 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:102:23 | 102 | fn putBit(b:bool, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:115:25 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0412]: cannot find type `ofstream` in this scope --> HuffmanCoding.rs:130:28 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:187:10 | 187 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:189:18 | 189 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:195:8 | 195 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:199:10 | 199 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:200:21 | 200 | writeTree(tree[0], ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:202:10 | 202 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:204:18 | 204 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:205:14 | 205 | putCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:210:18 | 210 | putBit(false, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:214:8 | 214 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:215:8 | 215 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:219:10 | 219 | binmode(ifh); | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:221:10 | 221 | binmode(ofh); | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:223:23 | 223 | tree = vec![readTree(ifh)]; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:226:18 | 226 | while getbyte(c,ifh) { | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:227:17 | 227 | lookupCode(c, ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ofh` in this scope --> HuffmanCoding.rs:229:8 | 229 | close(ofh)?; | ^^^ not found in this scope error[E0425]: cannot find value `ifh` in this scope --> HuffmanCoding.rs:230:8 | 230 | close(ifh)?; | ^^^ not found in this scope error[E0425]: cannot find function `exit` in this scope --> HuffmanCoding.rs:237:3 | 237 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | warning: unnecessary parentheses around `if` condition --> HuffmanCoding.rs:108:5 | 108 | if (partialBits == 8) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 108 - if (partialBits == 8) { 108 + if partialBits == 8 { | error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:15:2 | 15 | putbyte((i >> 8) & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:16:2 | 16 | putbyte(i & 0xFF,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:14:37 | 14 | fn putInt(i:isize, ofh:ofstream) -> 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[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:23:2 | 23 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyteNoCheck` in this scope --> HuffmanCoding.rs:26:2 | 26 | getbyteNoCheck(b,ifh); | ^^^^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:28:9 | 21 | fn getInt(ifh:ifstream) -> Result<isize, Arc<dyn error::Error>> { | ------------------------------------ expected `Result<isize, Arc<(dyn std::error::Error + 'static)>>` because of return type ... 28 | return i; | ^ expected `Result<isize, Arc<dyn Error>>`, found `isize` | = note: expected enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` found type `isize` help: try wrapping the expression in `Ok` | 28 | return Ok(i); | +++ + error[E0308]: mismatched types --> HuffmanCoding.rs:41:30 | 41 | fn new(v:isize, f:isize) -> Node { | --- ^^^^ expected `Node`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression error[E0308]: mismatched types --> HuffmanCoding.rs:47:28 | 47 | fn write(ofh:ofstream) -> 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[E0308]: mismatched types --> HuffmanCoding.rs:58:21 | 58 | let mut i:isize = list.len() - 2; | ----- ^^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 58 | let mut i:isize = (list.len() - 2).try_into().unwrap(); | + +++++++++++++++++++++ error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:14 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:34 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:59 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:80 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:105 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:64:121 | 64 | if list[j].frequency < list[j + 1].frequency || list[j].frequency == list[j + 1].frequency && list[j].value < l... | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:65:28 | 65 | let temp:Node = list[j + 1]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:12 | 66 | list[j + 1] = list[j]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:66:26 | 66 | list[j + 1] = list[j]; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0277]: the type `[Node]` cannot be indexed by `isize` --> HuffmanCoding.rs:67:12 | 67 | list[j] = temp; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[Node]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<Node>` to implement `Index<isize>` error[E0599]: no method named `write` found for struct `Node` in the current scope --> HuffmanCoding.rs:82:7 | 33 | struct Node { | ----------- method `write` not found for this struct ... 82 | node.write(ofh)?; | -----^^^^^----- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Node::write(node, ofh)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Node` --> HuffmanCoding.rs:47:2 | 47 | fn write(ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `write`, perhaps you need to implement one of them: candidate #1: `std::io::Write` candidate #2: `Hasher` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:84:18 | 84 | writeTree(node.left, ofh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:85:18 | 85 | writeTree(node.right, ofh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:83:22 | 83 | if node.value == -1 { | _________________________^ 84 | | writeTree(node.left, ofh)?; 85 | | writeTree(node.right, ofh)?; 86 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0308]: mismatched types --> HuffmanCoding.rs:91:19 | 91 | node = Node::new(getInt(ifh), 0)?; | --------- ^^^^^^^^^^^ expected `isize`, found `Result<isize, Arc<dyn Error>>` | | | arguments to this function are incorrect | = note: expected type `isize` found enum `Result<isize, Arc<(dyn std::error::Error + 'static)>>` note: associated function defined here --> HuffmanCoding.rs:41:5 | 41 | fn new(v:isize, f:isize) -> Node { | ^^^ ------- error[E0277]: the `?` operator can only be applied to values that implement `Try` --> HuffmanCoding.rs:91:9 | 91 | node = Node::new(getInt(ifh), 0)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Node` | = help: the trait `Try` is not implemented for `Node` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:93:8 | 93 | node.left = readTree(ifh)?; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:94:8 | 94 | node.right = readTree(ifh)?; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:96:9 | 89 | fn readTree(ifh:ifstream) -> Result<Node, Arc<dyn error::Error>> { | ----------------------------------- expected `Result<Node, Arc<dyn std::error::Error>>` because of return type ... 96 | return node; | ^^^^ expected `Result<Node, Arc<dyn Error>>`, found `Node` | = note: expected enum `Result<Node, Arc<dyn std::error::Error>>` found struct `Node` help: try wrapping the expression in `Ok` | 96 | return Ok(node); | +++ + error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:109:3 | 109 | putbyte(partialByte,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:108:24 | 108 | if (partialBits == 8) { | ___________________________^ 109 | | putbyte(partialByte,ofh); 110 | | partialByte = 0; 111 | | partialBits = 0; 112 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:116:10 | 116 | assert!(mapContains(huffmanCodes,c), "mapContains(huffmanCodes,c)"); | ^^^^^^^^^^^ not found in this scope error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:117:26 | 117 | let code = huffmanCodes.at(c); | ^^ method not found in `HashMap<i32, (isize, isize)>` error[E0308]: mismatched types --> HuffmanCoding.rs:121:3 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 121 | / while i_ < code.1 { 122 | | let b:bool = (code.0 & mask) != 0; 123 | | putBit(b, ofh)?; 124 | | mask >>= 1; 125 | | i_ += 1; 126 | | } | |_________^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:121:3 | 121 | while i_ < code.1 { | ^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on 122 | let b:bool = (code.0 & mask) != 0; 123 | putBit(b, ofh)?; | - if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 126 ~ } 127 ~ Ok(()) | error[E0069]: `return;` in a function whose return type is not `()` --> HuffmanCoding.rs:141:5 | 141 | return; | ^^^^^^ return type is not `()` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:145:17 | 145 | node = node.left; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:147:17 | 147 | node = node.right; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0425]: cannot find function `putbyte` in this scope --> HuffmanCoding.rs:153:3 | 153 | putbyte(node.value,ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:134:2 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | --------------------------------- expected `Result<(), Arc<(dyn std::error::Error + 'static)>>` because of return type ... 134 | / while partialBits > 0 { 135 | | let mut mask:isize = 1 << (partialBits - 1); 136 | | let mut node:Node = tree[0]; 137 | | let mut outputPath:isize = 0; ... | 155 | | partialByte &= !(outputPath << partialBits); 156 | | } | |_____^ expected `Result<(), Arc<dyn Error>>`, found `()` | = note: expected enum `Result<(), Arc<(dyn std::error::Error + 'static)>>` found unit type `()` note: the function expects a value to always be returned, but loops might run zero times --> HuffmanCoding.rs:134:2 | 134 | while partialBits > 0 { | ^^^^^^^^^^^^^^^^^^^^^ this might have zero elements to iterate on ... 141 | return; | ------ if the loop doesn't execute, this value would never get returned = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility help: try adding an expression at the end of the block | 156 ~ } 157 ~ Ok(()) | error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:162:30 | 162 | constructHuffmanCodes(node.left, newCode); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:162:36 | 162 | constructHuffmanCodes(node.left, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 162 | constructHuffmanCodes(node.left, newCode.into()); | +++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:164:30 | 164 | constructHuffmanCodes(node.right, newCode); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:164:37 | 164 | constructHuffmanCodes(node.right, newCode); | --------------------- ^^^^^^^ expected `(isize, isize)`, found `[isize; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[isize; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[isize; 2]` into `(isize, isize)` | 164 | constructHuffmanCodes(node.right, newCode.into()); | +++++++ error[E0308]: mismatched types --> HuffmanCoding.rs:166:16 | 166 | huffmanCodes[node.value] = code; | ^^^^^^^^^^ expected `&i32`, found `isize` error[E0433]: failed to resolve: use of undeclared type `Utils` --> HuffmanCoding.rs:171:11 | 171 | for k in Utils::keys(frequencies) { | ^^^^^ use of undeclared type `Utils` error[E0599]: no method named `at` found for struct `HashMap` in the current scope --> HuffmanCoding.rs:172:38 | 172 | tree.push(Node::new(k, frequencies.at(k))); | ^^ method not found in `HashMap<isize, isize>` error[E0308]: mismatched types --> HuffmanCoding.rs:174:27 | 174 | let mut treeSize:isize = tree.len(); | ----- ^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 174 | let mut treeSize:isize = tree.len().try_into().unwrap(); | ++++++++++++++++++++ error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:178:11 | 178 | newNode.right = tree.pop().unwrap(); | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:179:11 | 179 | newNode.left = tree.pop().unwrap(); | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `left` on type `Node` --> HuffmanCoding.rs:180:31 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0609]: no field `right` on type `Node` --> HuffmanCoding.rs:180:56 | 180 | newNode.frequency = newNode.left.frequency + newNode.right.frequency; | ^^^^^ unknown field | = note: available fields are: `value`, `frequency` error[E0308]: mismatched types --> HuffmanCoding.rs:182:14 | 174 | let mut treeSize:isize = tree.len(); | ----- expected due to this type ... 182 | treeSize = tree.len(); | ^^^^^^^^^^ expected `isize`, found `usize` error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:187:2 | 187 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:189:8 | 189 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `mapContains` in this scope --> HuffmanCoding.rs:190:7 | 190 | if !mapContains(frequencies,(c) as isize) { | ^^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:191:16 | 191 | frequencies[c] = 0; | ^ expected `&isize`, found `u8` error[E0308]: mismatched types --> HuffmanCoding.rs:193:15 | 193 | frequencies[c] += 1; | ^ expected `&isize`, found `u8` error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:195:2 | 195 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:186:45 | 186 | fn computeFrequencies(fromFilespec:&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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:199:2 | 199 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:202:2 | 202 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:204:8 | 204 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:205:11 | 205 | putCode(c, ofh)?; | ------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:115:4 | 115 | fn putCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 205 | putCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:214:2 | 214 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:215:2 | 215 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:198:56 | 198 | fn compressFile(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[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:219:2 | 219 | binmode(ifh); | ^^^^^^^ not found in this scope error[E0425]: cannot find function `binmode` in this scope --> HuffmanCoding.rs:221:2 | 221 | binmode(ofh); | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:223:14 | 223 | tree = vec![readTree(ifh)]; | ^^^^^^^^^^^^^ expected `Node`, found `Result<Node, Arc<dyn Error>>` | = note: expected struct `Node` found enum `Result<Node, Arc<(dyn std::error::Error + 'static)>>` error[E0425]: cannot find function `getbyte` in this scope --> HuffmanCoding.rs:226:8 | 226 | while getbyte(c,ifh) { | ^^^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:227:14 | 227 | lookupCode(c, ofh)?; | ---------- ^ expected `isize`, found `u8` | | | arguments to this function are incorrect | note: function defined here --> HuffmanCoding.rs:130:4 | 130 | fn lookupCode(c:isize, ofh:ofstream) -> Result<(), Arc<dyn error::Error>> { | ^^^^^^^^^^ ------- help: you can convert a `u8` to an `isize` | 227 | lookupCode(c.into(), ofh)?; | +++++++ error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:229:2 | 229 | close(ofh)?; | ^^^^^ not found in this scope error[E0425]: cannot find function `close` in this scope --> HuffmanCoding.rs:230:2 | 230 | close(ifh)?; | ^^^^^ not found in this scope error[E0308]: mismatched types --> HuffmanCoding.rs:218:58 | 218 | fn decompressFile(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[E0308]: mismatched types --> HuffmanCoding.rs:248:35 | 248 | constructHuffmanCodes(tree[0], startCode); | --------------------- ^^^^^^^^^ expected `(isize, isize)`, found `[{integer}; 2]` | | | arguments to this function are incorrect | = note: expected tuple `(isize, isize)` found array `[{integer}; 2]` note: function defined here --> HuffmanCoding.rs:159:4 | 159 | fn constructHuffmanCodes(node:Node, code:(isize, isize)) -> () { | ^^^^^^^^^^^^^^^^^^^^^ ------------------- help: call `Into::into` on this expression to convert `[{integer}; 2]` into `(isize, isize)` | 248 | constructHuffmanCodes(tree[0], startCode.into()); | +++++++ error[E0433]: failed to resolve: use of undeclared crate or module `io` --> HuffmanCoding.rs:259:59 | 259 | 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 110 previous errors; 1 warning emitted Some errors have detailed explanations: E0069, E0277, E0308, E0412, E0424, E0425, E0433, E0599, E0609. For more information about an error, try `rustc --explain E0069`. $ ls -al output/test100.* ls: output/test100.*: No such file or directory $ diff ../../data/text/100.txt output/test100.txt diff: output/test100.txt: No such file or directory

Solution