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.
Enum variants, naming & discriminant
Variant names are translated from the taxonomy-with-ids.en-US.txt file as follows:
- The leading ID is removed and used as discriminant for the enum variant.
- The immediately following characters
-are removed - All occurrences of
&are replaced withAnd - Non-alphanumeric ascii characters are removed
For example 1604 - Apparel & Accessories > Clothing becomes ApparelAndAccessoriesClothing.
The discriminant is represented as a u32 internally.
Examples
Try to parse an integer as a product category (i.e. from its ID)
use TryInto;
use ProductCategory;
let cat: ProductCategory = 3237.try_into.unwrap;
assert_eq!;
Get the number representation of the product category
use ProductCategory;
assert_eq!;
Get the name of a product category
use ProductCategory;
assert_eq!;
Serialize / deserialize with Serde