MCPcopy Create free account
hub / github.com/arraypad/each / guess_format

Function guess_format

src/formats/mod.rs:32–61  ·  view source on GitHub ↗
(
	ext: &Option<String>,
	reader: &mut CachedReader,
	formats: &'a IndexMap<&'static str, Box<dyn Format>>,
)

Source from the content-addressed store, hash-verified

30
31#[allow(clippy::borrowed_box)]
32pub 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}

Callers 1

runFunction · 0.85

Calls 4

readMethod · 0.80
rewindMethod · 0.80
get_extensionsMethod · 0.45
is_valid_headerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…