Skip to content

Commit 32a9de8

Browse files
authored
Merge pull request #3 from madsmtm/chores
Fix warnings, and other chores
2 parents 2a67179 + 30d83ea commit 32a9de8

35 files changed

+165
-136
lines changed

objc_foundation/examples/example.rs renamed to examples/foundation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate objc_foundation;
2-
31
use objc_foundation::{
42
INSArray, INSCopying, INSDictionary, INSObject, INSString, NSArray, NSDictionary, NSObject,
53
NSString,

objc_foundation/examples/custom_class.rs renamed to examples/foundation_custom_class.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#[macro_use]
2-
extern crate objc;
3-
extern crate objc_foundation;
4-
51
use std::sync::{Once, ONCE_INIT};
62

73
use objc::declare::ClassDecl;
4+
use objc::msg_send;
85
use objc::runtime::{Class, Object, Sel};
96
use objc::Message;
107
use objc_foundation::{INSObject, NSObject};

objc/examples/example.rs renamed to examples/objc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
#[macro_use]
2-
extern crate objc;
3-
41
use objc::rc::StrongPtr;
52
use objc::runtime::{Class, Object};
6-
use objc::Encode;
3+
use objc::{class, msg_send, Encode};
74

85
fn main() {
96
// Get a class

objc/src/declare.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The following example demonstrates declaring a class named `MyNumber` that has
1010
one ivar, a `u32` named `_number` and a `number` method that returns it:
1111
1212
``` no_run
13-
# #[macro_use] extern crate objc;
13+
# use objc::class;
1414
# use objc::declare::ClassDecl;
1515
# use objc::runtime::{Class, Object, Sel};
1616
# fn main() {
@@ -91,7 +91,7 @@ fn count_args(sel: Sel) -> usize {
9191
sel.name().chars().filter(|&c| c == ':').count()
9292
}
9393

94-
fn method_type_encoding(ret: &Encoding, args: &[Encoding]) -> CString {
94+
fn method_type_encoding(ret: &Encoding<'_>, args: &[Encoding<'_>]) -> CString {
9595
// First two arguments are always self and the selector
9696
let mut types = format!("{}{}{}", ret, <*mut Object>::ENCODING, Sel::ENCODING);
9797
for enc in args {
@@ -123,7 +123,7 @@ impl ClassDecl {
123123
if cls.is_null() {
124124
None
125125
} else {
126-
Some(ClassDecl { cls: cls })
126+
Some(ClassDecl { cls })
127127
}
128128
}
129129

@@ -159,8 +159,11 @@ impl ClassDecl {
159159
/// Adds a method with the given name and implementation to self.
160160
/// Panics if the method wasn't sucessfully added
161161
/// or if the selector and function take different numbers of arguments.
162-
/// Unsafe because the caller must ensure that the types match those that
163-
/// are expected when the method is invoked from Objective-C.
162+
///
163+
/// # Safety
164+
///
165+
/// The caller must ensure that the types match those that are expected
166+
/// when the method is invoked from Objective-C.
164167
pub unsafe fn add_method<F>(&mut self, sel: Sel, func: F)
165168
where
166169
F: MethodImplementation<Callee = Object>,
@@ -182,8 +185,11 @@ impl ClassDecl {
182185
/// Adds a class method with the given name and implementation to self.
183186
/// Panics if the method wasn't sucessfully added
184187
/// or if the selector and function take different numbers of arguments.
185-
/// Unsafe because the caller must ensure that the types match those that
186-
/// are expected when the method is invoked from Objective-C.
188+
///
189+
/// # Safety
190+
///
191+
/// The caller must ensure that the types match those that are expected
192+
/// when the method is invoked from Objective-C.
187193
pub unsafe fn add_class_method<F>(&mut self, sel: Sel, func: F)
188194
where
189195
F: MethodImplementation<Callee = Class>,
@@ -262,7 +268,7 @@ impl ProtocolDecl {
262268
if proto.is_null() {
263269
None
264270
} else {
265-
Some(ProtocolDecl { proto: proto })
271+
Some(ProtocolDecl { proto })
266272
}
267273
}
268274

objc/src/exception.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ use objc_exception;
33
use crate::rc::StrongPtr;
44
use crate::runtime::Object;
55

6+
// Comment copied from `objc_exception`
7+
8+
/// Tries to execute the given closure and catches an Objective-C exception
9+
/// if one is thrown.
10+
///
11+
/// Returns a `Result` that is either `Ok` if the closure succeeded without an
12+
/// exception being thrown, or an `Err` with a pointer to an exception if one
13+
/// was thrown. The exception is retained and so must be released.
14+
///
15+
/// # Safety
16+
///
17+
/// This encourages unwinding through the closure from Objective-C, which is
18+
/// not safe.
619
pub unsafe fn catch_exception<F, R>(closure: F) -> Result<R, StrongPtr>
720
where
821
F: FnOnce() -> R,

objc/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Objective-C Runtime bindings and wrapper for Rust.
66
Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html) macro:
77
88
``` no_run
9-
# #[macro_use] extern crate objc;
9+
# use objc::{class, msg_send};
1010
# use objc::runtime::{BOOL, Class, Object};
1111
# fn main() {
1212
# unsafe {
@@ -63,11 +63,7 @@ The bindings can be used on Linux or *BSD utilizing the
6363
#![crate_name = "objc"]
6464
#![crate_type = "lib"]
6565
#![warn(missing_docs)]
66-
67-
extern crate malloc_buf;
68-
extern crate objc_encode;
69-
#[cfg(feature = "exception")]
70-
extern crate objc_exception;
66+
#![allow(clippy::missing_safety_doc)]
7167

7268
pub use objc_encode::{Encode, Encoding};
7369

objc/src/macros.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ To check for a class that may not exist, use `Class::get`.
66
77
# Example
88
``` no_run
9-
# #[macro_use] extern crate objc;
109
# fn main() {
1110
let cls = class!(NSObject);
1211
# }
@@ -31,7 +30,6 @@ Registers a selector, returning a `Sel`.
3130
3231
# Example
3332
```
34-
# #[macro_use] extern crate objc;
3533
# fn main() {
3634
let sel = sel!(description);
3735
let sel = sel!(setObject:forKey:);
@@ -64,7 +62,6 @@ Variadic arguments are not currently supported.
6462
6563
# Example
6664
``` no_run
67-
# #[macro_use] extern crate objc;
6865
# use objc::runtime::Object;
6966
# fn main() {
7067
# unsafe {

objc/src/message/apple/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
{
4343
let sup = Super {
4444
receiver: obj as *mut T as *mut Object,
45-
superclass: superclass,
45+
superclass,
4646
};
4747
let receiver = &sup as *const Super as *mut Object;
4848
let msg_send_fn = msg_send_super_fn::<R>();

objc/src/message/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub unsafe trait Message {
7070
send_message(self, sel, args)
7171
}
7272

73+
#[allow(missing_docs)]
7374
#[cfg(feature = "verify_message")]
7475
unsafe fn send_message<A, R>(&self, sel: Sel, args: A) -> Result<R, MessageError>
7576
where
@@ -90,7 +91,7 @@ pub unsafe trait Message {
9091
9192
# Example
9293
``` no_run
93-
# #[macro_use] extern crate objc;
94+
# use objc::{class, msg_send};
9495
# use objc::runtime::{BOOL, Class, Object};
9596
# use objc::Message;
9697
# fn main() {
@@ -195,7 +196,7 @@ Currently, an error may be returned in two cases:
195196
pub struct MessageError(String);
196197

197198
impl fmt::Display for MessageError {
198-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
199200
fmt::Display::fmt(&self.0, f)
200201
}
201202
}
@@ -207,7 +208,7 @@ impl Error for MessageError {
207208
}
208209

209210
impl<'a> From<VerificationError<'a>> for MessageError {
210-
fn from(err: VerificationError) -> MessageError {
211+
fn from(err: VerificationError<'_>) -> MessageError {
211212
MessageError(err.to_string())
212213
}
213214
}
@@ -284,8 +285,7 @@ where
284285

285286
#[cfg(test)]
286287
mod tests {
287-
use super::Message;
288-
use crate::runtime::Object;
288+
use super::*;
289289
use crate::test_utils;
290290

291291
#[test]

objc/src/message/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum VerificationError<'a> {
1212
}
1313

1414
impl<'a> fmt::Display for VerificationError<'a> {
15-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1616
match *self {
1717
VerificationError::NilReceiver(sel) => {
1818
write!(f, "Messsaging {:?} to nil", sel)
@@ -55,7 +55,7 @@ impl<'a> fmt::Display for VerificationError<'a> {
5555
}
5656
}
5757

58-
pub fn verify_message_signature<A, R>(cls: &Class, sel: Sel) -> Result<(), VerificationError>
58+
pub fn verify_message_signature<A, R>(cls: &Class, sel: Sel) -> Result<(), VerificationError<'_>>
5959
where
6060
A: EncodeArguments,
6161
R: Encode,

0 commit comments

Comments
 (0)