Skip to content

Commit

Permalink
use Bens fork with mozilla/uniffi-rs#2087 and the BagOfBytes works! c…
Browse files Browse the repository at this point in the history
…an be used in other crates than declaring crate.
  • Loading branch information
Sajjon committed May 20, 2024
1 parent 32e5740 commit 2582a00
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 15 deletions.
52 changes: 42 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
]

[workspace.dependencies]
uniffi = { git = "https://github.com/mozilla/uniffi-rs/", rev = "aa338ccb435d81d36f7adef8954bcffebdd4a7d1" }
uniffi = { git = "https://github.com/bendk/uniffi-rs/", rev = "4b65c3796bc3743404e1ee2a7b4ab51e24589aa6" }

[profile.release]
incremental = false
Expand Down
2 changes: 1 addition & 1 deletion crates/chef/src/chef.udl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
namespace chef {};
namespace chef {};
2 changes: 2 additions & 0 deletions crates/chef/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::ops::AddAssign;
pub struct Chef {
pub name: String,
pub money: RwLock<Money>,
pub bag_of_bytes: BagOfBytes,
}

#[uniffi::export]
Expand All @@ -16,6 +17,7 @@ impl Chef {
Arc::new(Self {
name,
money: RwLock::new(money),
bag_of_bytes: BagOfBytes::from(vec![0xde, 0xad, 0xbe, 0xef]),
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/kitchen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build = "build.rs"

[dependencies]
uniffi = { workspace = true, features = ["cli"] }
money = { path = "../money" }
farm = { path = "../farm" }

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/kitchen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod prelude {
pub use crate::models::*;

pub(crate) use farm::prelude::*;
pub(crate) use money::prelude::*;
}

pub use prelude::*;
Expand Down
4 changes: 3 additions & 1 deletion crates/kitchen/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::prelude::*;

#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, uniffi::Record)]
#[derive(Default, Clone, Debug, PartialEq, Eq, uniffi::Record)]
pub struct Fridge {
pub egg: EggBox,
pub butter: ButterBlock,
pub lemons: Lemons,
pub bag_of_bytes: BagOfBytes,
}
impl Fridge {
pub fn stock_with(produce: farm::Produce) -> Self {
Self {
egg: EggBox::from(produce.clone()),
butter: ButterBlock::from(produce.clone()),
lemons: Lemons::from(produce.clone()),
bag_of_bytes: BagOfBytes::from(vec![0xde, 0xad, 0xbe, 0xef]),
}
}
}
Expand Down
32 changes: 31 additions & 1 deletion crates/lemon_meringue_pie/tests/bindings/pie_baking.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.sajjon.meringue.*
import com.sajjon.lemon.filling.*
import com.sajjon.kitchen.*

fun test() {
fun test_bake_pie() {
val chef = Chef(name = "Auguste Gusteau", money = Money(amount = 50u))
val farm = Farm(money = Money(amount = 200u))
val produce = farm.produce()
Expand All @@ -23,4 +23,34 @@ fun test() {
assert(farm.balance() == 175.toULong())
}

fun test_bag_of_bytes() {
val f0 = Fridge(
egg = EggBox.TWELVE,
butter = ButterBlock(weight = 1u),
lemons = Lemons(count = 1u),
bagOfBytes = listOf(1.toUByte())
)
val f1 = Fridge(
egg = EggBox.TWELVE,
butter = ButterBlock(weight = 1u),
lemons = Lemons(count = 1u),
bagOfBytes = listOf(1.toUByte())
)
assert(f0 == f1)

var x = newBagOfBytesFromHexString(hex = "adbe")
var y = newBagOfBytesFromHexString(hex = "adbe")
x = newBagOfBytesPrependDe(bagOfBytes = x)
x = newBagOfBytesAppendEf(bagOfBytes = x)
y = newBagOfBytesAppendEf(bagOfBytes = y)
y = newBagOfBytesPrependDe(bagOfBytes = y)
assert(x == y)
assert(bagOfBytesToHexString(bagOfBytes = x) == "deadbeef")
}

fun test() {
test_bake_pie()
test_bag_of_bytes()
}

test()
2 changes: 2 additions & 0 deletions crates/money/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"
build = "build.rs"

[dependencies]
itertools = "0.13.0"
hex = "0.4.3"
uniffi = { workspace = true, features = ["cli"] }

[build-dependencies]
Expand Down
Loading

0 comments on commit 2582a00

Please sign in to comment.