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