Przeglądaj źródła

docs: Add function documentation for get_file_type and icon_for_file.

Robert Minsk 2 lat temu
rodzic
commit
2a357db2d3
2 zmienionych plików z 10 dodań i 4 usunięć
  1. 8 4
      src/info/filetype.rs
  2. 2 0
      src/output/icons.rs

+ 8 - 4
src/info/filetype.rs

@@ -233,9 +233,12 @@ const EXTENSION_TYPES: Map<&'static str, FileType> = phf_map! {
 };
 
 #[derive(Debug)]
-pub struct FileExtensions;
+pub struct FileTypeClassifier;
 
-impl FileExtensions {
+impl FileTypeClassifier {
+    /// Lookup the file type based on the file's name, by the file name
+    /// lowercase extension, or if the file could be compiled from related
+    /// source code.
     fn get_file_type(file: &File<'_>) -> Option<FileType> {
         // Case-insensitive readme is checked first for backwards compatibility.
         if file.name.to_lowercase().starts_with("readme") {
@@ -259,11 +262,12 @@ impl FileExtensions {
     }
 }
 
-impl FileColours for FileExtensions {
+impl FileColours for FileTypeClassifier {
+    /// Map from the file type to the display style/color for the file.
     fn colour_file(&self, file: &File<'_>) -> Option<Style> {
         use ansi_term::Colour::*;
 
-        match FileExtensions::get_file_type(file) {
+        match FileTypeClassifier::get_file_type(file) {
             Some(FileType::Compiled)   => Some(Yellow.normal()),
             Some(FileType::Compressed) => Some(Red.normal()),
             Some(FileType::Crypto)     => Some(Green.bold()),

+ 2 - 0
src/output/icons.rs

@@ -500,6 +500,8 @@ pub fn iconify_style(style: Style) -> Style {
          .unwrap_or_default()
 }
 
+/// Lookup the icon for a file based on the file's name, if the entry is a
+/// directory, or by the lowercase file extension.
 pub fn icon_for_file(file: &File<'_>) -> char {
     if let Some(icon) = FILENAME_ICONS.get(file.name.as_str()) {
         *icon