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 std::collections::HashMap;

use crate::{
    SourceMethod,
    Dependencies
};

use serde::{Serialize,Deserialize};

/// Represents a source set in a multiplatform project.
#[derive(Deserialize, Serialize, Debug, PartialEq)]
pub struct SourceSet<'a> {
    /// The name of the source set.
    pub name: &'a str,
    /// The source method for the source set, indicating whether it is obtained or created.
    pub source_method: SourceMethod,
    /// The dependencies that the source set depends on.
    pub depends_on: HashMap<&'a str, &'a str>,
    /// The dependencies included in the source set.
    pub dependencies: Dependencies<'a>,
}

impl<'a> SourceSet<'a> {
    /// Creates a new `SourceSet` instance with the specified parameters.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the source set.
    /// * `source_method` - The source method of the source set.
    /// * `depends_on` - The dependencies of the source set.
    /// * `dependencies` - The dependencies of the source set.
    ///
    /// # Example
    ///
    /// ```
    /// use std::collections::HashMap;
    /// use kmmp_structure::gradle::{
    ///     SourceSet,
    ///     sourcesets::SourceMethod,
    ///     dependency::Dependencies
    /// };
    ///
    /// let depends_on: HashMap<&str, &str> = HashMap::new();
    /// let dependencies = Dependencies::new(&Vec::new());
    /// let source_set = SourceSet::new("main", SourceMethod::Kotlin, &depends_on, dependencies);
    /// ```
    pub fn new(
        name: &'a str,
        source_method: SourceMethod,
        depends_on: HashMap<&'a str, &'a str>,
        dependencies: Dependencies<'a>,
    ) -> Self {
        SourceSet {
            name,
            source_method,
            depends_on,
            dependencies,
        }
    }
}

impl std::fmt::Display for SourceSet<'_> {
    /// Formats the `SourceSet` as a string.
    ///
    /// # Example
    ///
    /// ```
    /// use std::collections::HashMap;
    /// use kmmp_structure::gradle::{
    ///     SourceSet,
    ///     sourcesets::SourceMethod,
    ///     dependency::Dependencies
    /// };
    ///
    /// let depends_on: HashMap<&str, &str> = HashMap::new();
    /// let dependencies = Dependencies::new(&Vec::new());
    /// let source_set = SourceSet::new("main", SourceMethod::Getting, &depends_on, dependencies);
    /// assert_eq!(
    ///     source_set.to_string(),
    ///     "val main by getting { }\n"
    /// );
    /// ```
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f,"val {} by {}",self.name,self.source_method.to_string())?;
        if !self.depends_on.is_empty() || !self.dependencies.as_list().is_empty() {
            write!(f," {{\n")?;

            for (receiver,parameter) in &self.depends_on {
                if *receiver != "this" {
                    write!(f,"{}.",receiver)?;
                };
                write!(f,"dependsOn({})",parameter)?;
            };

            write!(f,"{}",self.dependencies.to_string())?;
            write!(f," }}\n")?;
        }
        Ok(())
    }
}