fork download
  1. pub fn read_file(path : &str) -> Result<Vec<String>, io::Error> {
  2. let contents = fs::read_to_string(path)
  3. .expect("Something went wrong reading the file");
  4. println!("{}", contents);
  5. Ok(contents.split('\n').map(|s| s.to_string()).collect())
  6. }
  7.  
  8. pub fn last_n_lines(vec : &Vec<String>, line : usize) -> Vec<String> {
  9. vec.iter().enumerate().filter(|&(i, _)| i >= line).map(|(_, e)| e.to_string()).collect()
  10. }
  11.  
  12. pub fn join(vec : &Vec<String>, delim : &String) -> String {
  13. vec.join(delim)
  14. }
  15.  
  16.  
  17. // THIS FUNCTION CALLS THE REST
  18. pub fn read_markdown_file(path : &str) -> Result<Markdown, io::Error> {
  19. let vdocument = read_file(path)?;
  20. let front_matter_end = match vdocument.iter().rposition(|x| x == "---") {
  21. Some(x) => x+1,
  22. None => 0,
  23. };
  24. let markdown = join(&last_n_lines(&vdocument, front_matter_end), &String::from("\n"));
  25.  
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
error[E0433]: failed to resolve: use of undeclared type or module `io`
 --> prog.rs:1:54
  |
1 | pub fn read_file(path : &str) -> Result<Vec<String>, io::Error> {
  |                                                      ^^ use of undeclared type or module `io`

error[E0433]: failed to resolve: use of undeclared type or module `fs`
 --> prog.rs:2:20
  |
2 |     let contents = fs::read_to_string(path)
  |                    ^^ use of undeclared type or module `fs`

error[E0433]: failed to resolve: use of undeclared type or module `io`
  --> prog.rs:18:60
   |
18 | pub fn read_markdown_file(path : &str) -> Result<Markdown, io::Error> {
   |                                                            ^^ use of undeclared type or module `io`

error[E0412]: cannot find type `Markdown` in this scope
  --> prog.rs:18:50
   |
18 | pub fn read_markdown_file(path : &str) -> Result<Markdown, io::Error> {
   |                                                  ^^^^^^^^ not found in this scope

error[E0601]: `main` function not found in crate `prog`
  |
  = note: consider adding a `main` function to `prog.rs`

error: aborting due to 5 previous errors

Some errors occurred: E0412, E0433, E0601.
For more information about an error, try `rustc --explain E0412`.
stdout
Standard output is empty