rustc 1.59.0 (9d1b2106e 2022-02-23) on win11-64 (I am beginner)
The code is from
https://youtu.be/xNrglKGi-7o?t=337
use std::fs::read_to_string;
fn main() {
let input: String = read_to_string ("file.txt").unwrap() ;
let good_lines: Vec<_> = input: String
.lines(): Lines //std::io::Lines; //std::str::Lines
.filter(|l |capital_letter (l)): impl Iterator<Itm = &str>
.collect();
dbg!(good_lines);
}
#[allow(unused)]
fn capital_letter(s: &str)->bool{
matches!(s.chars().next(),Some(c)if c.is_uppercase() )
}
/////////////////////////
casts cannot be followed by a method call
cannot find type `Lines` in this scope
`impl Trait` not allowed outside of function and method return types
/////////////////////////
Compiling file v0.1.0 (file)
error: casts cannot be followed by a method call
--> src\main.rs:4:30
|
4 | let good_lines: Vec<_> = input: String
| ^^^^^^^^^^^^^
|
help: try surrounding the expression in parentheses
|
4 | let good_lines: Vec<_> = (input: String)
| + +
error: casts cannot be followed by a method call
--> src\main.rs:4:30
|
4 | let good_lines: Vec<_> = input: String
| ______________________________^
5 | | .lines(): Lines
| |_______________________^
|
help: try surrounding the expression in parentheses
|
4 ~ let good_lines: Vec<_> = (input: String
5 ~ .lines(): Lines)
|
error: casts cannot be followed by a method call
--> src\main.rs:4:30
|
4 | let good_lines: Vec<_> = input: String
| ______________________________^
5 | | .lines(): Lines
6 | | .filter(|l |capital_letter (l)): impl Iterator<Itm = &str>
| |__________________________________________________________________^
|
help: try surrounding the expression in parentheses
|
4 ~ let good_lines: Vec<_> = (input: String
5 | .lines(): Lines
6 ~ .filter(|l |capital_letter (l)): impl Iterator<Itm = &str>)
|
error[E0412]: cannot find type `Lines` in this scope
--> src\main.rs:5:19
|
5 | .lines(): Lines
| ^^^^^ expecting a type here because of type ascription
|
help: consider importing one of these items
|
1 | use core::str::Lines;
|
1 | use std::io::Lines;
|
1 | use std::str::Lines;
|
error[E0562]: `impl Trait` not allowed outside of function and method return types
--> src\main.rs:6:42
|
6 | .filter(|l |capital_letter (l)): impl Iterator<Itm = &str>
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Some errors have detailed explanations: E0412, E0562.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `file` due to 5 previous errors
The terminal process " cargo.exe 'run', '--package', 'file', '--bin', 'file'" terminated with exit code: 101.