-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Objc category inheritance #1784
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0bedb67
Added Categories to objective-c inheritance.
simlay bcd3d7f
Removed derive Clones in favor of a tupple.
simlay 1367006
Removed unneeded methods in tests
simlay 079571d
A pretty gross implementation :/
simlay 3ad80d9
Updated comment
simlay 70f38c6
cargo fmt
simlay 7a642c3
Added get_parent_ty to clean up the option branches
simlay a04e151
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 5118d3e
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay ade5901
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay c162325
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 670331c
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 996af2e
Remove autogenerated comment
simlay 924182b
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 5c93c5c
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay a2287a3
Added fixed stuff from minor nits
simlay b9615e6
fix for rustfmt
simlay d19f52e
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 999133e
Merge branch 'objc-category-inheritance' of github.com:simlay/rust-bi…
simlay 84a3de9
Added loop for resolving typerefs.
simlay 6a2c809
Merge branch 'objc-category-inheritance' of github.com:simlay/rust-bi…
simlay a70adff
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay 0ce8926
Fixes from merging master into feature branch
simlay 78bf091
rustfmt and updated changelog
simlay 6663c80
Merge branch 'master' of github.com:rust-lang/rust-bindgen into objc-…
simlay bd5f919
maybe fix cargo fmt
simlay 4c00a97
fix cargo fmt
simlay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
#![cfg(target_os = "macos")] | ||
|
||
#[macro_use] | ||
extern crate objc; | ||
#[allow(non_camel_case_types)] | ||
pub type id = *mut objc::runtime::Object; | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Foo(pub id); | ||
impl std::ops::Deref for Foo { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Foo {} | ||
impl Foo { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) | ||
} | ||
} | ||
impl IFoo for Foo {} | ||
pub trait IFoo: Sized + std::ops::Deref {} | ||
impl Foo_BarCategory for Foo {} | ||
pub trait Foo_BarCategory: Sized + std::ops::Deref {} | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Bar(pub id); | ||
impl std::ops::Deref for Bar { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Bar {} | ||
impl Bar { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) | ||
} | ||
} | ||
impl IFoo for Bar {} | ||
impl Foo_BarCategory for Bar {} | ||
impl From<Bar> for Foo { | ||
fn from(child: Bar) -> Foo { | ||
Foo(child.0) | ||
} | ||
} | ||
impl std::convert::TryFrom<Foo> for Bar { | ||
type Error = &'static str; | ||
fn try_from(parent: Foo) -> Result<Bar, Self::Error> { | ||
let is_kind_of: bool = | ||
unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; | ||
if is_kind_of { | ||
Ok(Bar(parent.0)) | ||
} else { | ||
Err("This Foo cannot be downcasted to Bar") | ||
} | ||
} | ||
} | ||
impl IBar for Bar {} | ||
pub trait IBar: Sized + std::ops::Deref {} |
50 changes: 50 additions & 0 deletions
50
tests/expectations/tests/objc_category_template_inheritance.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
#![cfg(target_os = "macos")] | ||
|
||
#[macro_use] | ||
extern crate objc; | ||
#[allow(non_camel_case_types)] | ||
pub type id = *mut objc::runtime::Object; | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Foo(pub id); | ||
impl std::ops::Deref for Foo { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Foo {} | ||
impl Foo { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) | ||
} | ||
} | ||
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {} | ||
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {} | ||
impl<ObjectType: 'static> Foo_Baz<ObjectType> for Foo {} | ||
pub trait Foo_Baz<ObjectType>: Sized + std::ops::Deref {} | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Bar(pub id); | ||
impl std::ops::Deref for Bar { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Bar {} | ||
impl Bar { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) | ||
} | ||
} | ||
impl<ObjectType: 'static> IFoo<ObjectType> for Bar {} | ||
impl<ObjectType: 'static> Foo_Baz<ObjectType> for Bar {} | ||
impl<ObjectType: 'static> IBar<ObjectType> for Bar {} | ||
pub trait IBar<ObjectType>: Sized + std::ops::Deref {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
#![cfg(target_os = "macos")] | ||
|
||
#[macro_use] | ||
extern crate objc; | ||
#[allow(non_camel_case_types)] | ||
pub type id = *mut objc::runtime::Object; | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Foo(pub id); | ||
impl std::ops::Deref for Foo { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Foo {} | ||
impl Foo { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) | ||
} | ||
} | ||
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {} | ||
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {} | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct Bar(pub id); | ||
impl std::ops::Deref for Bar { | ||
type Target = objc::runtime::Object; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { &*self.0 } | ||
} | ||
} | ||
unsafe impl objc::Message for Bar {} | ||
impl Bar { | ||
pub fn alloc() -> Self { | ||
Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) | ||
} | ||
} | ||
impl<ObjectType: 'static> IFoo<ObjectType> for Bar {} | ||
impl<ObjectType: 'static> IBar<ObjectType> for Bar {} | ||
pub trait IBar<ObjectType>: Sized + std::ops::Deref {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// bindgen-flags: --objc-extern-crate -- -x objective-c | ||
// bindgen-osx-only | ||
|
||
@interface Foo | ||
@end | ||
|
||
@interface Foo (BarCategory) | ||
@end | ||
|
||
@interface Bar: Foo | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// bindgen-flags: --objc-extern-crate -- -x objective-c | ||
// bindgen-osx-only | ||
|
||
@interface Foo<__covariant ObjectType> | ||
@end | ||
|
||
@interface Foo<__covariant ObjectType> (Baz) | ||
@end | ||
|
||
@interface Bar<__covariant ObjectType>: Foo | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// bindgen-flags: --objc-extern-crate -- -x objective-c | ||
// bindgen-osx-only | ||
|
||
@interface Foo<__covariant ObjectType> | ||
@end | ||
|
||
@interface Bar<__covariant ObjectType>: Foo | ||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't these be
ItemId
s?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be
ItemId
s. After seeing #1889, it looks like you can use categories to add more protocol conformance :/