From 44a9e377371006f01f2e425fbf8d49e43bc14a9b Mon Sep 17 00:00:00 2001 From: Awad Mackie Date: Sun, 25 Nov 2018 21:17:18 +0000 Subject: [PATCH] ignore/types: add method for retrieving file type definition Fixes #1116, Closes #1120 --- ignore/src/types.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ignore/src/types.rs b/ignore/src/types.rs index 74c27c4..d7a1fc7 100644 --- a/ignore/src/types.rs +++ b/ignore/src/types.rs @@ -350,6 +350,18 @@ impl<'a> Glob<'a> { fn unmatched() -> Glob<'a> { Glob(GlobInner::UnmatchedIgnore) } + + /// Return the file type defintion that matched, if one exists. A file type + /// definition always exists when a specific definition matches a file + /// path. + pub fn file_type_def(&self) -> Option<&FileTypeDef> { + match self { + Glob(GlobInner::UnmatchedIgnore) => None, + Glob(GlobInner::Matched { def, .. }) => { + Some(def) + }, + } + } } /// A single file type definition.