Skip to content

Commit

Permalink
borsh: Add discriminant param for rust enum
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Jan 28, 2022
1 parent 4cdea04 commit 1ff0fc7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/borsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@project-serum/borsh",
"version": "0.2.2",
"version": "0.2.4",
"description": "Serum Borsh",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/borsh/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ export interface EnumLayout<T> extends Layout<T> {
export function rustEnum<T>(
variants: Layout<any>[],
property?: string,
discriminant?: Layout<any>,
): EnumLayout<T> {
const unionLayout = union(u8(), property);
const unionLayout = union(discriminant ?? u8(), property);
variants.forEach((variant, index) =>
unionLayout.addVariant(index, variant, variant.property),
);
Expand Down

0 comments on commit 1ff0fc7

Please sign in to comment.