vx_tool_rust/
rust_plugin.rs

1//! Rust plugin implementation
2
3use crate::rust_tool::CargoTool;
4use vx_plugin::{VxPlugin, VxTool};
5
6/// Rust plugin that provides Rust toolchain tools
7#[derive(Debug, Default)]
8pub struct RustPlugin;
9
10impl RustPlugin {
11    pub fn new() -> Self {
12        Self
13    }
14}
15
16#[async_trait::async_trait]
17impl VxPlugin for RustPlugin {
18    fn name(&self) -> &str {
19        "rust"
20    }
21
22    fn description(&self) -> &str {
23        "Rust toolchain support for vx"
24    }
25
26    fn version(&self) -> &str {
27        env!("CARGO_PKG_VERSION")
28    }
29
30    fn tools(&self) -> Vec<Box<dyn VxTool>> {
31        vec![Box::new(CargoTool::new())]
32    }
33
34    fn supports_tool(&self, tool_name: &str) -> bool {
35        matches!(tool_name, "cargo")
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_rust_plugin_creation() {
45        let plugin = RustPlugin::new();
46        assert_eq!(plugin.name(), "rust");
47        assert!(!plugin.description().is_empty());
48    }
49
50    #[test]
51    fn test_rust_plugin_tools() {
52        let plugin = RustPlugin::new();
53        let tools = plugin.tools();
54
55        assert_eq!(tools.len(), 1);
56
57        let tool_names: Vec<&str> = tools.iter().map(|t| t.name()).collect();
58        assert!(tool_names.contains(&"cargo"));
59    }
60
61    #[test]
62    fn test_rust_plugin_supports_tool() {
63        let plugin = RustPlugin::new();
64
65        assert!(plugin.supports_tool("cargo"));
66        assert!(!plugin.supports_tool("rustc"));
67        assert!(!plugin.supports_tool("rustup"));
68        assert!(!plugin.supports_tool("rustdoc"));
69        assert!(!plugin.supports_tool("rustfmt"));
70        assert!(!plugin.supports_tool("clippy"));
71        assert!(!plugin.supports_tool("nonexistent"));
72    }
73
74    #[test]
75    fn test_rust_plugin_version() {
76        let plugin = RustPlugin::new();
77        assert!(!plugin.version().is_empty());
78    }
79}