Skip to content

Commit

Permalink
fix: bindings had conflict between enums and structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dubadub committed Dec 16, 2024
1 parent 028de0a commit 8e7a811
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,3 @@ harness = false

[workspace]
members = [".", "playground", "bindings", "fuzz"]

[profile.release]
strip = true
2 changes: 1 addition & 1 deletion bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cooklang-bindings"
version = "0.14.0"
version = "0.14.1"
edition = "2021"
authors = ["dubadub <dubovskoy.a@gmail.com>"]
description = "Cooklang Uniffi bindings"
Expand Down
22 changes: 11 additions & 11 deletions bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ pub fn parse_metadata(input: String) -> CooklangMetadata {
pub fn deref_component(recipe: &CooklangRecipe, item: Item) -> Component {
match item {
Item::IngredientRef { index } => {
Component::Ingredient(recipe.ingredients.get(index as usize).unwrap().clone())
Component::IngredientComponent(recipe.ingredients.get(index as usize).unwrap().clone())
}
Item::CookwareRef { index } => {
Component::Cookware(recipe.cookware.get(index as usize).unwrap().clone())
Component::CookwareComponent(recipe.cookware.get(index as usize).unwrap().clone())
}
Item::TimerRef { index } => {
Component::Timer(recipe.timers.get(index as usize).unwrap().clone())
Component::TimerComponent(recipe.timers.get(index as usize).unwrap().clone())
}
Item::Text { value } => Component::Text(value),
Item::Text { value } => Component::TextComponent(value),
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ a test @step @salt{1%mg} more text
.next()
.expect("No blocks found")
{
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected first block to be a Step"),
}
.items,
Expand Down Expand Up @@ -388,7 +388,7 @@ Cook @onions{3%large} until brown

assert_eq!(
match note_block {
Block::Note(note) => note,
Block::NoteBlock(note) => note,
_ => panic!("Expected first block to be a Note"),
}
.text,
Expand All @@ -401,7 +401,7 @@ Cook @onions{3%large} until brown

assert_eq!(
match step_block {
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected second block to be a Step"),
}
.items,
Expand Down Expand Up @@ -445,7 +445,7 @@ simmer for 10 minutes

assert_eq!(
match first_block {
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected first block to be a Step"),
}
.items,
Expand All @@ -463,7 +463,7 @@ simmer for 10 minutes
// Check second step
assert_eq!(
match second_block {
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected second block to be a Step"),
}
.items,
Expand Down Expand Up @@ -510,7 +510,7 @@ Combine @cheese{100%g} and @spinach{50%g}, then season to taste.
.expect("No blocks found");
assert_eq!(
match first_block {
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected block to be a Step"),
}
.items,
Expand Down Expand Up @@ -541,7 +541,7 @@ Combine @cheese{100%g} and @spinach{50%g}, then season to taste.
.expect("No blocks found");
assert_eq!(
match second_block {
Block::Step(step) => step,
Block::StepBlock(step) => step,
_ => panic!("Expected block to be a Step"),
}
.items,
Expand Down
16 changes: 8 additions & 8 deletions bindings/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ pub struct Section {

#[derive(uniffi::Enum, Debug)]
pub enum Block {
Step(Step),
Note(BlockNote),
StepBlock(Step),
NoteBlock(BlockNote),
}

#[derive(uniffi::Enum, Debug, PartialEq)]
pub enum Component {
Ingredient(Ingredient),
Cookware(Cookware),
Timer(Timer),
Text(String),
IngredientComponent(Ingredient),
CookwareComponent(Cookware),
TimerComponent(Timer),
TextComponent(String),
}

#[derive(uniffi::Record, Debug)]
Expand Down Expand Up @@ -382,7 +382,7 @@ pub(crate) fn into_simple_recipe(recipe: &OriginalRecipe) -> CooklangRecipe {
};
items.push(item);
}
blocks.push(Block::Step(Step {
blocks.push(Block::StepBlock(Step {
items,
ingredient_refs: step_ingredient_refs.clone(),
cookware_refs: step_cookware_refs.clone(),
Expand All @@ -394,7 +394,7 @@ pub(crate) fn into_simple_recipe(recipe: &OriginalRecipe) -> CooklangRecipe {
}

cooklang::Content::Text(text) => {
blocks.push(Block::Note(BlockNote {
blocks.push(Block::NoteBlock(BlockNote {
text: text.to_string(),
}));
}
Expand Down

0 comments on commit 8e7a811

Please sign in to comment.