Project: Head and Tail
Write a filter program that prints the first and last few lines from an input stream. The single command line parameter will specify the number of lines from the head and tail to print. The program should print a line "..." between the first lines and the last lines.
Output
$ rustc HeadAndTail.rs
error[E0425]: cannot find value `Utils` in this scope
--> HeadAndTail.rs:13:14
|
13 | maxLines = Utils.stoiWithDefault(args[1], 10);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> HeadAndTail.rs:16:50
|
16 | let mut buffer:Vec<String> = Vec::with_capacity(maxLines);
| ------------------ ^^^^^^^^ expected `usize`, found `isize`
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> /opt/local/libexec/rust/src/rustc-1.71.1-src/library/alloc/src/vec/mod.rs:478:12
help: you can convert an `isize` to a `usize` and panic if the converted value doesn't fit
|
16 | let mut buffer:Vec<String> = Vec::with_capacity(maxLines.try_into().unwrap());
| ++++++++++++++++++++
error[E0425]: cannot find function `getline` in this scope
--> HeadAndTail.rs:19:8
|
19 | while getline(line) {
| ^^^^^^^ not found in this scope
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:20:10
|
20 | buffer[count % maxLines] = String::from(line);
| ^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:31:27
|
31 | println!("{}", buffer[i]);
| ^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:40:27
|
40 | println!("{}", buffer[(count + i) % maxLines]);
| ^^^^^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0277, E0308, E0425.
For more information about an error, try `rustc --explain E0277`.
$ rustc HeadAndTail.rs
error[E0425]: cannot find value `Utils` in this scope
--> HeadAndTail.rs:13:14
|
13 | maxLines = Utils.stoiWithDefault(args[1], 10);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> HeadAndTail.rs:16:50
|
16 | let mut buffer:Vec<String> = Vec::with_capacity(maxLines);
| ------------------ ^^^^^^^^ expected `usize`, found `isize`
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> /opt/local/libexec/rust/src/rustc-1.71.1-src/library/alloc/src/vec/mod.rs:478:12
help: you can convert an `isize` to a `usize` and panic if the converted value doesn't fit
|
16 | let mut buffer:Vec<String> = Vec::with_capacity(maxLines.try_into().unwrap());
| ++++++++++++++++++++
error[E0425]: cannot find function `getline` in this scope
--> HeadAndTail.rs:19:8
|
19 | while getline(line) {
| ^^^^^^^ not found in this scope
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:20:10
|
20 | buffer[count % maxLines] = String::from(line);
| ^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:31:27
|
31 | println!("{}", buffer[i]);
| ^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error[E0277]: the type `[String]` cannot be indexed by `isize`
--> HeadAndTail.rs:40:27
|
40 | println!("{}", buffer[(count + i) % maxLines]);
| ^^^^^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[String]>` is not implemented for `isize`
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `Vec<String>` to implement `Index<isize>`
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0277, E0308, E0425.
For more information about an error, try `rustc --explain E0277`.