From 8c195f224b6ffb601b054c0484671bb929b45b5e Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 21 Apr 2023 22:01:11 +0200 Subject: [PATCH] =?UTF-8?q?impl=20sync=20and=20send=20for=20types=20(?= =?UTF-8?q?=F0=9F=A5=B4)=20as=20well=20as=20"AsObject"=20for=20casting=20f?= =?UTF-8?q?or=20objects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sdk/output/rust.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/sdk/output/rust.rs b/src/sdk/output/rust.rs index 0124559..ec40951 100644 --- a/src/sdk/output/rust.rs +++ b/src/sdk/output/rust.rs @@ -160,6 +160,9 @@ pub fn generate_class(class: &Class, _sdk: &Sdk, w: &mut W) -> anyhow: if !is_class { writeln!(w, "pub struct {name}(UnsafeCell<[u8; {size}]>);")?; + writeln!(w, "unsafe impl Send for {name} {{}}")?; + writeln!(w, "unsafe impl Sync for {name} {{}}")?; + write!( w, r#" @@ -187,6 +190,24 @@ impl {name} {{ } else { writeln!(w, "pub struct {name}(NonNull>);")?; + writeln!(w, "unsafe impl Send for {name} {{}}")?; + writeln!(w, "unsafe impl Sync for {name} {{}}")?; + + write!( + w, + r#" +impl AsUObject for {name} {{ + fn as_uobject(&self) -> UObject {{ + UObject(self.0) + }} + + fn from_uobject(obj: UObject) -> Self {{ + Self(obj.0) + }} +}} +"# + )?; + write!( w, r#"