reovim_module_codec_utf8/
lib.rs1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3use std::sync::Arc;
26
27use {
28 reovim_driver_codec::{ContentClassifierStore, ContentCodecFactoryStore},
29 reovim_kernel::api::v1::{Module, ModuleContext, ModuleError, ModuleId, ProbeResult, Version},
30};
31
32pub mod classifier;
33pub mod codec;
34pub mod factory;
35
36pub use {classifier::Utf8Classifier, codec::Utf8Codec, factory::Utf8CodecFactory};
37
38pub struct CodecUtf8Module;
42
43impl CodecUtf8Module {
44 #[must_use]
46 pub const fn new() -> Self {
47 Self
48 }
49}
50
51#[cfg_attr(coverage_nightly, coverage(off))]
52impl Default for CodecUtf8Module {
53 fn default() -> Self {
54 Self::new()
55 }
56}
57
58impl Module for CodecUtf8Module {
59 fn id(&self) -> ModuleId {
60 ModuleId::new("codec-utf8")
61 }
62
63 fn name(&self) -> &'static str {
64 "Codec UTF-8"
65 }
66
67 fn version(&self) -> Version {
68 Version::new(0, 1, 0)
69 }
70
71 #[cfg_attr(coverage_nightly, coverage(off))]
72 fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
73 let factory_store = ctx.services.get_or_create::<ContentCodecFactoryStore>();
75 factory_store.add_factory(Arc::new(Utf8CodecFactory::new()));
76
77 let classifier_store = ctx.services.get_or_create::<ContentClassifierStore>();
79 classifier_store.add(Arc::new(Utf8Classifier::new()));
80
81 tracing::info!("CodecUtf8Module: registered UTF-8 codec and classifier");
82 ProbeResult::Success
83 }
84
85 fn exit(&mut self) -> Result<(), ModuleError> {
86 tracing::info!("CodecUtf8Module: exiting");
87 Ok(())
88 }
89
90 fn provides(&self) -> &[&'static str] {
91 &[reovim_capabilities::CODEC_PROVIDER]
92 }
93}
94
95#[cfg(feature = "dynamic")]
97reovim_module_macros::declare_module!(CodecUtf8Module);
98
99#[cfg(test)]
100#[path = "lib_tests.rs"]
101mod tests;