kmmp_project_manager/gradle/dependency/dependencies.rs
1use crate::Dependency;
2
3use serde::{Deserialize,Serialize};
4
5/// Represents a collection of dependencies.
6#[derive(Deserialize, Serialize, Debug, PartialEq, PartialOrd )]
7#[serde(bound(deserialize = "'de: 'a"))]
8pub struct Dependencies<'a> (Vec<Dependency<'a>>);
9
10impl<'a> Dependencies<'a> {
11 /// Returns a reference to the underlying vector of dependencies.
12 pub fn as_list(&self) -> &Vec<Dependency<'a>> {
13 &self.0
14 }
15}
16
17impl<'a> From<Vec<Dependency<'a>>> for Dependencies<'a> {
18 /// Creates a new `Dependencies` instance from vector.
19 ///
20 /// # Example
21 ///
22 /// ```
23 /// use kmmp_project_manager::{Dependency,Dependencies};
24 ///
25 /// let dependencies = vec![
26 /// Dependency::new(/* dependency details */),
27 /// // Add more dependencies if needed
28 /// ];
29 ///
30 /// let deps = Dependencies::from(dependencies);
31 /// ```
32 fn from(vector : Vec<Dependency<'a>>) -> Self {
33 Self(vector)
34 }
35}
36
37impl std::fmt::Display for Dependencies<'_> {
38 /// Formats the `Dependencies` as a string.
39 ///
40 /// # Example
41 ///
42 /// ```
43 /// use kmmp_project_manager::{Dependency,Dependencies};
44 ///
45 /// let dependencies = vec![
46 /// Dependency::new(/* dependency details */),
47 /// // Add more dependencies if needed
48 /// ];
49 ///
50 /// let deps = Dependencies::new(&dependencies);
51 /// assert_eq!(deps.to_string(), "dependencies {\n /* formatted list of dependencies */\n}\n");
52 /// ```
53 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54 write!(f,"dependencies {{\n")?;
55 for dependency in &self.0 {
56 write!(f, " {}\n", dependency.to_string())?;
57 };
58 write!(f,"}}\n")
59 }
60}