Skip to content

Commit

Permalink
Use immutable reference in a few places where now necessary
Browse files Browse the repository at this point in the history
See madsmtm/objc2#150 for a bit of background
  • Loading branch information
madsmtm committed Aug 1, 2023
1 parent e77801c commit c71be85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/input/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ use crate::input::{TextFieldDelegate, TEXTFIELD_DELEGATE_PTR};
use crate::utils::load;

/// Called when editing this text field has ended (e.g. user pressed enter).
extern "C" fn text_did_end_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
view.text_did_end_editing(s.to_str());
}

extern "C" fn text_did_begin_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
view.text_did_begin_editing(s.to_str());
}

extern "C" fn text_did_change<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_change<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
view.text_did_change(s.to_str());
}

extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) -> BOOL {
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, stringValue] });

Expand All @@ -34,7 +34,7 @@ extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &mut Object,
}
}

extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) -> BOOL {
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
match view.text_should_end_editing(s.to_str()) {
Expand Down
10 changes: 5 additions & 5 deletions src/input/uikit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ use crate::input::{TextFieldDelegate, TEXTFIELD_DELEGATE_PTR};
use crate::utils::load;

/// Called when editing this text field has ended (e.g. user pressed enter).
extern "C" fn text_did_end_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, text] });
view.text_did_end_editing(s.to_str());
}

extern "C" fn text_did_begin_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, text] });
view.text_did_begin_editing(s.to_str());
}

extern "C" fn text_did_change<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) {
extern "C" fn text_did_change<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, text] });
view.text_did_change(s.to_str());
}

extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) -> BOOL {
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, text] });

Expand All @@ -38,7 +38,7 @@ extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &mut Object,
}
}

extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &mut Object, _: Sel, _info: id) -> BOOL {
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
let s = NSString::retain(unsafe { msg_send![this, text] });
match view.text_should_end_editing(s.to_str()) {
Expand Down
8 changes: 4 additions & 4 deletions src/view/controller/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::utils::load;
use crate::view::{ViewDelegate, VIEW_DELEGATE_PTR};

/// Called when the view controller receives a `viewWillAppear` message.
extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
extern "C" fn will_appear<T: ViewDelegate>(this: &Object, _: Sel) {
unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewWillAppear];
}
Expand All @@ -21,7 +21,7 @@ extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
}

/// Called when the view controller receives a `viewDidAppear` message.
extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
extern "C" fn did_appear<T: ViewDelegate>(this: &Object, _: Sel) {
unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewDidAppear];
}
Expand All @@ -31,7 +31,7 @@ extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
}

/// Called when the view controller receives a `viewWillDisappear` message.
extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
extern "C" fn will_disappear<T: ViewDelegate>(this: &Object, _: Sel) {
unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewWillDisappear];
}
Expand All @@ -41,7 +41,7 @@ extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
}

/// Called when the view controller receives a `viewDidDisappear` message.
extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
extern "C" fn did_disappear<T: ViewDelegate>(this: &Object, _: Sel) {
unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewDidDisappear];
}
Expand Down
8 changes: 4 additions & 4 deletions src/view/controller/uikit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::utils::load;
use crate::view::{ViewDelegate, VIEW_DELEGATE_PTR};

/// Called when the view controller receives a `viewWillAppear:` message.
extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
extern "C" fn will_appear<T: ViewDelegate>(this: &Object, _: Sel, animated: BOOL) {
unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillAppear: animated];
}
Expand All @@ -21,7 +21,7 @@ extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated:
}

/// Called when the view controller receives a `viewDidAppear:` message.
extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
extern "C" fn did_appear<T: ViewDelegate>(this: &Object, _: Sel, animated: BOOL) {
unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidAppear: animated];
}
Expand All @@ -31,7 +31,7 @@ extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: B
}

/// Called when the view controller receives a `viewWillDisappear:` message.
extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
extern "C" fn will_disappear<T: ViewDelegate>(this: &Object, _: Sel, animated: BOOL) {
unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillDisappear: animated];
}
Expand All @@ -41,7 +41,7 @@ extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animate
}

/// Called when the view controller receives a `viewDidDisappear:` message.
extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
extern "C" fn did_disappear<T: ViewDelegate>(this: &Object, _: Sel, animated: BOOL) {
unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidDisappear: animated];
}
Expand Down

0 comments on commit c71be85

Please sign in to comment.