Skip to content

Commit

Permalink
Documentation for new modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed Jan 23, 2024
1 parent 7f27f9e commit 8a04d17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions genealogos/src/cyclonedx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! # CycloneDX
//!
//! This module contains the `cyclonedx` module, which is responsible for providing a uniform interface for generating CycloneDX output.
mod version;

use crate::Result;
Expand All @@ -6,11 +10,15 @@ pub use version::Version;

use crate::model::Model;

#[derive(Debug, Clone)]
/// Combines the two CycloneDX versions into a single enum
pub enum CycloneDX {
V1_4(cyclonedx::v_1_4::CycloneDx),
V1_5(cyclonedx::v_1_5::CycloneDx),
}

/// Converts a `Model` into a `CycloneDX` struct
/// `From` was not implemented for `Model` and `CycloneDX` because of the CycloneDX version
impl CycloneDX {
pub(crate) fn from_model(model: Model, version: Version) -> Result<Self> {
match version {
Expand All @@ -20,6 +28,8 @@ impl CycloneDX {
}
}

/// Serializes a `CycloneDX` struct into a CycloneDX JSON string
/// We dispatch to the correct version here, removing the overhead of the CycloneDX enum
impl serde::Serialize for CycloneDX {
fn serialize<S: serde::Serializer>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions genealogos/src/cyclonedx/version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! CycloneDX version enum
//!
//! This module contains the `Version` enum, which represents the CycloneDX version to use
//! when generating CycloneDX output.
use clap::ValueEnum;

#[derive(Debug, Clone)]
Expand All @@ -6,6 +11,8 @@ pub enum Version {
V1_5,
}

/// This trait is used to convert a `Version` into a `PossibleValue` for clap
/// And ensures that clap can display the possible values for `Version`
impl ValueEnum for Version {
fn value_variants<'a>() -> &'a [Self] {
&[Version::V1_4, Version::V1_5]
Expand Down

0 comments on commit 8a04d17

Please sign in to comment.