Skip to main content

ass_editor/extensions/registry_integration/
adapters.rs

1//! Adapters bridging editor extensions to ass-core handler traits.
2//!
3//! Provides [`EditorTagHandlerAdapter`] and [`EditorSectionProcessorAdapter`],
4//! which let editor extensions act as ass-core `TagHandler`s and
5//! `SectionProcessor`s respectively.
6
7use crate::extensions::EditorExtension;
8use ass_core::plugin::{SectionProcessor, SectionResult, TagHandler, TagResult};
9
10#[cfg(not(feature = "std"))]
11use alloc::{boxed::Box, string::String};
12
13/// Adapter that allows editor extensions to provide tag handlers
14#[allow(dead_code)]
15pub struct EditorTagHandlerAdapter {
16    extension_name: String,
17    tag_name: String,
18    extension: Box<dyn EditorExtension>,
19}
20
21impl EditorTagHandlerAdapter {
22    /// Create a new tag handler adapter
23    pub fn new(
24        extension_name: String,
25        tag_name: String,
26        extension: Box<dyn EditorExtension>,
27    ) -> Self {
28        Self {
29            extension_name,
30            tag_name,
31            extension,
32        }
33    }
34}
35
36impl TagHandler for EditorTagHandlerAdapter {
37    fn name(&self) -> &'static str {
38        // This is a limitation - we need to leak the string to get a 'static lifetime
39        Box::leak(self.tag_name.clone().into_boxed_str())
40    }
41
42    fn process(&self, _args: &str) -> TagResult {
43        // Extensions process tags through their command system
44        // This is a simplified implementation
45        TagResult::Processed
46    }
47
48    fn validate(&self, args: &str) -> bool {
49        !args.is_empty()
50    }
51}
52
53/// Adapter that allows editor extensions to provide section processors
54#[allow(dead_code)]
55pub struct EditorSectionProcessorAdapter {
56    extension_name: String,
57    section_name: String,
58    extension: Box<dyn EditorExtension>,
59}
60
61impl EditorSectionProcessorAdapter {
62    /// Create a new section processor adapter
63    pub fn new(
64        extension_name: String,
65        section_name: String,
66        extension: Box<dyn EditorExtension>,
67    ) -> Self {
68        Self {
69            extension_name,
70            section_name,
71            extension,
72        }
73    }
74}
75
76impl SectionProcessor for EditorSectionProcessorAdapter {
77    fn name(&self) -> &'static str {
78        // This is a limitation - we need to leak the string to get a 'static lifetime
79        Box::leak(self.section_name.clone().into_boxed_str())
80    }
81
82    fn process(&self, _header: &str, _lines: &[&str]) -> SectionResult {
83        // Extensions process sections through their command system
84        // This is a simplified implementation
85        SectionResult::Processed
86    }
87
88    fn validate(&self, header: &str, lines: &[&str]) -> bool {
89        !header.is_empty() && !lines.is_empty()
90    }
91}