Skip to content

Commit 0ce8926

Browse files
committed
Fixes from merging master into feature branch
1 parent a70adff commit 0ce8926

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

src/codegen/mod.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,6 +3980,28 @@ impl CodeGenerator for ObjCInterface {
39803980
result.push(impl_trait);
39813981
}
39823982
}
3983+
for (category_name, category_template_names) in
3984+
&parent.categories
3985+
{
3986+
let category_name = ctx.rust_ident(category_name);
3987+
let impl_trait = if !category_template_names.is_empty()
3988+
{
3989+
let template_names: Vec<Ident> =
3990+
category_template_names
3991+
.iter()
3992+
.map(|g| ctx.rust_ident(g))
3993+
.collect();
3994+
quote! {
3995+
impl <#(#template_names :'static),*> #category_name <#(#template_names),*> for #class_name {
3996+
}
3997+
}
3998+
} else {
3999+
quote! {
4000+
impl #category_name for #class_name { }
4001+
}
4002+
};
4003+
result.push(impl_trait);
4004+
}
39834005
if !parent.is_template() {
39844006
let parent_struct_name = parent.name();
39854007
let child_struct_name = self.name();
@@ -4011,28 +4033,6 @@ impl CodeGenerator for ObjCInterface {
40114033
}
40124034
};
40134035
result.push(try_into_block);
4014-
for (category_name, category_template_names) in
4015-
&parent.categories
4016-
{
4017-
let category_name = ctx.rust_ident(category_name);
4018-
let impl_trait = if !category_template_names.is_empty()
4019-
{
4020-
let template_names: Vec<Ident> =
4021-
category_template_names
4022-
.iter()
4023-
.map(|g| ctx.rust_ident(g))
4024-
.collect();
4025-
quote! {
4026-
impl <#(#template_names :'static),*> #category_name <#(#template_names),*> for #class_name {
4027-
}
4028-
}
4029-
} else {
4030-
quote! {
4031-
impl #category_name for #class_name { }
4032-
}
4033-
};
4034-
result.push(impl_trait);
4035-
}
40364036
parent.parent_class
40374037
} else {
40384038
None

tests/expectations/tests/objc_category_inheritance.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate objc;
1111
#[allow(non_camel_case_types)]
1212
pub type id = *mut objc::runtime::Object;
1313
#[repr(transparent)]
14-
#[derive(Clone, Copy)]
14+
#[derive(Clone)]
1515
pub struct Foo(pub id);
1616
impl std::ops::Deref for Foo {
1717
type Target = objc::runtime::Object;
@@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref {}
3030
impl Foo_BarCategory for Foo {}
3131
pub trait Foo_BarCategory: Sized + std::ops::Deref {}
3232
#[repr(transparent)]
33-
#[derive(Clone, Copy)]
33+
#[derive(Clone)]
3434
pub struct Bar(pub id);
3535
impl std::ops::Deref for Bar {
3636
type Target = objc::runtime::Object;
@@ -46,5 +46,22 @@ impl Bar {
4646
}
4747
impl IFoo for Bar {}
4848
impl Foo_BarCategory for Bar {}
49+
impl From<Bar> for Foo {
50+
fn from(child: Bar) -> Foo {
51+
Foo(child.0)
52+
}
53+
}
54+
impl std::convert::TryFrom<Foo> for Bar {
55+
type Error = &'static str;
56+
fn try_from(parent: Foo) -> Result<Bar, Self::Error> {
57+
let is_kind_of: bool =
58+
unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) };
59+
if is_kind_of {
60+
Ok(Bar(parent.0))
61+
} else {
62+
Err("This Foo cannot be downcasted to Bar")
63+
}
64+
}
65+
}
4966
impl IBar for Bar {}
5067
pub trait IBar: Sized + std::ops::Deref {}

tests/expectations/tests/objc_category_template_inheritance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate objc;
1111
#[allow(non_camel_case_types)]
1212
pub type id = *mut objc::runtime::Object;
1313
#[repr(transparent)]
14-
#[derive(Clone, Copy)]
14+
#[derive(Clone)]
1515
pub struct Foo(pub id);
1616
impl std::ops::Deref for Foo {
1717
type Target = objc::runtime::Object;
@@ -30,7 +30,7 @@ pub trait IFoo<ObjectType>: Sized + std::ops::Deref {}
3030
impl<ObjectType: 'static> Foo_Baz<ObjectType> for Foo {}
3131
pub trait Foo_Baz<ObjectType>: Sized + std::ops::Deref {}
3232
#[repr(transparent)]
33-
#[derive(Clone, Copy)]
33+
#[derive(Clone)]
3434
pub struct Bar(pub id);
3535
impl std::ops::Deref for Bar {
3636
type Target = objc::runtime::Object;

tests/expectations/tests/objc_template_inheritance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate objc;
1111
#[allow(non_camel_case_types)]
1212
pub type id = *mut objc::runtime::Object;
1313
#[repr(transparent)]
14-
#[derive(Clone, Copy)]
14+
#[derive(Clone)]
1515
pub struct Foo(pub id);
1616
impl std::ops::Deref for Foo {
1717
type Target = objc::runtime::Object;
@@ -28,7 +28,7 @@ impl Foo {
2828
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
2929
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {}
3030
#[repr(transparent)]
31-
#[derive(Clone, Copy)]
31+
#[derive(Clone)]
3232
pub struct Bar(pub id);
3333
impl std::ops::Deref for Bar {
3434
type Target = objc::runtime::Object;

0 commit comments

Comments
 (0)