reovim_module_codec_utf8/
classifier.rs1use reovim_driver_codec::{ContentClassifier, ContentType};
7
8pub struct Utf8Classifier;
14
15impl Utf8Classifier {
16 #[must_use]
18 pub const fn new() -> Self {
19 Self
20 }
21}
22
23#[cfg_attr(coverage_nightly, coverage(off))]
24impl Default for Utf8Classifier {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl ContentClassifier for Utf8Classifier {
31 fn classify(&self, raw: &[u8], _path: &str) -> Option<ContentType> {
32 if std::str::from_utf8(raw).is_ok() {
33 Some(ContentType::new(ContentType::UTF8))
34 } else {
35 None
36 }
37 }
38
39 fn priority(&self) -> u8 {
40 10
41 }
42
43 fn name(&self) -> &'static str {
44 "utf-8"
45 }
46}
47
48#[cfg(test)]
49#[path = "classifier_tests.rs"]
50mod tests;