kmmp-project-manager 0.1.0

kmmp-project-manager is a Rust crate for Kotlin Multiplatform (KMP) projects, offering a lightweight alternative to Android Studio. It provides tools for project creation, structure management, build automation, code generation, IDE integration, dependency management, and project configuration.
Documentation
use serde::{Deserialize,Serialize};

/// Represents a plugin identifier.
#[derive(Deserialize, Serialize, Debug, PartialEq, PartialOrd)]
pub struct PluginIndentifier<'a> {
    /// The name of the plugin.
    pub name: &'a str,
    /// Indicates whether the standard library is supported by the plugin.
    pub is_standard_library_supported: bool,
    /// The version of the plugin (optional).
    pub version: Option<&'a str>,
    /// Indicates whether the plugin should be applied (optional).
    pub apply: Option<bool>,
}

impl<'a> PluginIndentifier<'a> {
    /// Creates a new `PluginIndentifier` instance with the specified name and standard library support.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the plugin.
    /// * `is_standard_library_supported` - A flag indicating whether the plugin supports the standard library.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_project_manager::PluginIndentifier;
    ///
    /// let plugin = PluginIndentifier::new("plugin_name", true);
    /// ```
    pub const fn new(name: &'a str, is_standard_library_supported: bool) -> Self {
        PluginIndentifier {
            name,
            is_standard_library_supported,
            version: None,
            apply: None,
        }
    }

    /// Sets the version for the plugin.
    ///
    /// # Arguments
    ///
    /// * `version` - The version of the plugin.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_project_manager::PluginIndentifier;
    ///
    /// let plugin = PluginIndentifier::new("plugin_name", true)
    ///     .with_version("1.0.0");
    /// ```
    pub const fn with_version(mut self, version: &'a str) -> Self {
        self.version = Some(version);
        self
    }

    /// Sets the apply flag for the plugin.
    ///
    /// # Arguments
    ///
    /// * `apply` - A flag indicating whether the plugin should be applied.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_project_manager::PluginIndentifier;
    ///
    /// let plugin = PluginIndentifier::new("plugin_name", true)
    ///     .with_apply(true);
    /// ```
    pub const fn with_apply(mut self, apply: bool) -> Self {
        self.apply = Some(apply);
        self
    }
}

impl std::fmt::Display for PluginIndentifier<'_> {
    /// Formats the `PluginIndentifier` as a string.
    ///
    /// # Example
    ///
    /// ```
    /// let plugin = PluginIndentifier::new("plugin_name", true)
    ///     .with_version(Some("1.0.0"))
    ///     .with_apply(Some(true));
    ///
    /// assert_eq!(plugin.to_string(), "kotlin(\"plugin_name\") version \"1.0.0\" apply \"true\"");
    /// ```
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 
        let prefix = if self.is_standard_library_supported { "kotlin" }
        else { "id" };

        let version = match self.version {
            None => String::new(),
            Some(value) => format!("version \"{}\"",value),
        };

        let apply = match self.apply {
            None => String::new(),
            Some(value) => format!("apply \"{}\"",value.to_string()),
        };
        
        write!(f,"{}(\"{}\") {} {}",&prefix,self.name,version,apply)?;
        Ok(())
    }
}