rust for learning.
                  
                  
                  It just prints files of current directory.
                  
                  
                  
                  
                  
                  I'm unable to print OsStr (returned by file_name()) as it does not have Display trait. How to print then?
                  
                  
                  
                  
                  
                  Code is here:
                  
                  
                  
                  
                  
                  use std::{env, fs, path::PathBuf};
                  
                  
                  
                  
                  
                  fn main() {
                  
                  
                      let path = env::current_dir().unwrap();
                  
                  
                      let items = get_dir_items(&path);
                  
                  
                  
                  
                  
                      for item in items {
                  
                  
                          println!("{}", item.file_name().unwrap())
                  
                  
                      }
                  
                  
                  }
                  
                  
                  
                  
                  
                  fn get_dir_items(path: &PathBuf) -> Vec<PathBuf> {
                  
                  
                      let items: Vec<PathBuf> = fs::read_dir(path)
                  
                  
                          .unwrap()
                  
                  
                          .map(|item| item.unwrap())
                  
                  
                          .map(|entry| entry.path())
                  
                  
                          .collect();
                  
                  
                      items
                  
                  
                  }
                  
                  
                
there is a method for printing, to_str()
 Sudeep
                          
                        
                      
                    
                    
                    
                    
                      Автор вопроса
                      
                      
                        
                          Sudeep
                          
                        
                      
                    
                    
                    
                    
                      Автор вопроса
                    
                    
                  Yeah working: println!("{}", item.file_name().unwrap().to_str().unwrap())
Обсуждают сегодня