( ext: &Option<String>, reader: &mut CachedReader, formats: &'a IndexMap<&'static str, Box<dyn Format>>, )
| 30 | |
| 31 | #[allow(clippy::borrowed_box)] |
| 32 | pub fn guess_format<'a>( |
| 33 | ext: &Option<String>, |
| 34 | reader: &mut CachedReader, |
| 35 | formats: &'a IndexMap<&'static str, Box<dyn Format>>, |
| 36 | ) -> Option<&'a Box<dyn Format>> { |
| 37 | if let Some(ref ext) = ext { |
| 38 | for (_, format) in formats { |
| 39 | for pe in format.get_extensions() { |
| 40 | if ext == pe { |
| 41 | return Some(format); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | let mut header = [0; CACHE_LEN]; |
| 48 | if reader.read(&mut header).is_ok() { |
| 49 | reader.rewind(); |
| 50 | |
| 51 | for (_, format) in formats { |
| 52 | if let Ok(is_header) = format.is_valid_header(&header) { |
| 53 | if is_header { |
| 54 | return Some(format); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | None |
| 61 | } |
no test coverage detected
searching dependent graphs…