Google Taxonomy / Product Categories
The purpose of this crate is to more easily work with Google Product Categories / Taxonomy.
This is provided via the google_taxonomy::ProductCategory enum which contains all categories that exist as of 2021-08-13.
Examples
From
use std::convert::TryInto;
use google_taxonomy::ProductCategory;
let cat: ProductCategory = 3237.try_into().unwrap();
assert_eq!(cat, ProductCategory::AnimalsAndPetSuppliesLiveAnimals);
Get the number representation of the product category
use google_taxonomy::ProductCategory;
assert_eq!(ProductCategory::AnimalsAndPetSuppliesLiveAnimals as u32, 3237);
Get the name of a product category
use google_taxonomy::ProductCategory;
assert_eq!(ProductCategory::AnimalsAndPetSuppliesLiveAnimals.to_string(), "Animals & Pet Supplies > Live Animals");
Serialize
#[cfg(feature = "with-serde")]
{
use serde::{Deserialize, Serialize};
use google_taxonomy::ProductCategory;
#[derive(Deserialize, Serialize, Debug, PartialEq)]
struct Product {
category: ProductCategory,
}
let serialized = r#"{"category":"Animals & Pet Supplies"}"#;
let deserialized: Product = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, Product { category: ProductCategory::AnimalsAndPetSupplies });
assert_eq!(serde_json::to_string(&deserialized).unwrap(), serialized);
}