Skip to content

Commit

Permalink
Add serde support to PackageType
Browse files Browse the repository at this point in the history
This adds both serialization and deserialization to the `PackageType`
enum, based on its lowercase representation.
  • Loading branch information
cd-work committed Dec 17, 2024
1 parent 0d332fa commit 170e9fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion purl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package-type = ["phf", "unicase"]
hex = "0.4.3"
percent-encoding = "2.2.0"
phf = { version = "0.11.1", features = ["macros", "unicase"], optional = true }
serde = { version = "1.0.150", optional = true }
serde = { version = "1.0.150", optional = true, features = ["derive"] }
smartstring = { version = "1.0.1", optional = true }
thiserror = "1.0.37"
unicase = { version = "2.6.0", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions purl/src/package_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::fmt;
use std::str::FromStr;

use phf::phf_map;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use unicase::UniCase;

use crate::{
Expand Down Expand Up @@ -134,6 +136,8 @@ pub type PurlBuilder = GenericPurlBuilder<PackageType>;
///
/// This is a subset of the types described in the PURL spec repository. See
/// [`Purl`] for details.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum PackageType {
Expand Down

0 comments on commit 170e9fb

Please sign in to comment.