Skip to content

Commit ee2afe2

Browse files
authored
Merge pull request #452 from madsmtm/doc
Improve examples and remove words that downplay the difficulty of a given task
2 parents 1c3f05c + d5a6ccf commit ee2afe2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+419
-342
lines changed

crates/block-sys/README.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,27 @@ see that for related crates.
1313

1414
## Runtime Support
1515

16-
This library is basically just a raw interface to the aptly specified [Blocks
17-
ABI](https://clang.llvm.org/docs/Block-ABI-Apple.html). However, different
18-
runtime implementations exist and act in slightly different ways (and have
19-
several different helper functions), the most important aspect being that the
20-
libraries are named differently, so the linking must take that into account.
21-
22-
The user can choose the desired runtime by using the relevant cargo feature
23-
flags, see the following sections (might have to disable the default `apple`
16+
This library is a raw interface to the aptly specified [Blocks ABI][abi].
17+
However, different runtime implementations exist and act in slightly different
18+
ways (and have several different helper functions), the most important aspect
19+
being that the libraries are named differently, so the linking must take that
20+
into account.
21+
22+
You can choose the desired runtime by using the relevant cargo feature flags,
23+
see the following sections (you might have to disable the default `apple`
2424
feature first). Note that if the `objc-sys` crate is present in the module
2525
tree, this should have the same feature flag enabled as that.
2626

2727

28+
[abi]: https://clang.llvm.org/docs/Block-ABI-Apple.html
29+
30+
2831
### Apple's [`libclosure`](https://github.com/apple-oss-distributions/libclosure)
2932

3033
- Feature flag: `apple`.
3134

32-
This is naturally the most sophisticated runtime, and it has quite a lot more
33-
features than the specification mandates. This is used by default.
35+
This is the most sophisticated runtime, and it has quite a lot more features
36+
than the specification mandates. It is used by default.
3437

3538
The minimum required operating system versions are as follows:
3639
- macOS: `10.6`
@@ -45,11 +48,11 @@ Though in practice Rust itself requires higher versions than this.
4548

4649
- Feature flag: `compiler-rt`.
4750

48-
This is effectively just a copy of Apple's older (around macOS 10.6) runtime,
49-
and is now used in [Swift's `libdispatch`] and [Swift's Foundation] as well.
51+
This is a copy of Apple's older (around macOS 10.6) runtime, and is now used
52+
in [Swift's `libdispatch`] and [Swift's Foundation] as well.
5053

51-
This can be easily used on many Linux systems with the `libblocksruntime-dev`
52-
package.
54+
The runtime and associated headers can be installed on many Linux systems with
55+
the `libblocksruntime-dev` package.
5356

5457
Using this runtime probably won't work together with `objc-sys` crate.
5558

@@ -77,8 +80,8 @@ Sources:
7780

7881
**Unstable: Hasn't been tested on Windows yet!**
7982

80-
Essentially just [a fork](https://github.com/microsoft/libobjc2) based on
81-
GNUStep's `libobjc2` version 1.8.
83+
[A fork](https://github.com/microsoft/libobjc2) based on GNUStep's `libobjc2`
84+
version 1.8.
8285

8386

8487
### [`ObjFW`](https://github.com/ObjFW/ObjFW)

crates/block-sys/build.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ fn main() {
3030

3131
match (apple, compiler_rt, gnustep, objfw) {
3232
(true, false, false, false) => {
33-
// Link to libclosure (internally called libsystem_blocks), which is
34-
// exported by libSystem.dylib.
33+
// Link to libclosure (internally called libsystem_blocks), which
34+
// is exported by libSystem.dylib.
3535
//
36-
// Note that System.framework is just a deprecated wrapper over the
37-
// dynamic library.
36+
// Note: Don't get confused by the presence of `System.framework`,
37+
// it is a deprecated wrapper over the dynamic library, so we'd
38+
// rather use the latter.
3839
println!("cargo:rustc-link-lib=dylib=System");
3940
// Alternative: Only link to libsystem_blocks.dylib
4041
// println!("cargo:rustc-link-search=native=/usr/lib/system");

crates/block-sys/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub struct Block_layout {
284284
/// }
285285
/// ```
286286
///
287-
/// But it is safe to access this through just `Block_descriptor_header`.
287+
/// But since all of these start with `Block_descriptor_header`, it is
288+
/// always safe to reinterpret this pointer as that.
288289
// Note: Important to use `*const c_void` until we know which type it is!
289290
pub descriptor: *const c_void,
290291
}

crates/block2/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
Apple's C language extension of blocks in Rust.
99

10-
This crate provides functionality for interracting with C blocks, which is
11-
effectively the C-equivalent of Rust's closures.
10+
This crate provides functionality for interracting with C blocks, which is the
11+
C-equivalent of Rust's closures.
1212

1313
They are _technically_ not limited to only being used in Objective-C, though
1414
in practice it's likely the only place you'll ever encounter them.

crates/block2/src/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ block_args_impl!(
9090
#[repr(C)]
9191
pub struct Block<A, R> {
9292
_inner: [u8; 0],
93-
// We effectively store `Block_layout` + a bit more, but `Block` has to
94-
// remain an empty type otherwise the compiler thinks we only have
95-
// provenance over `Block_layout`.
93+
// We store `Block_layout` + a bit more, but `Block` has to remain an
94+
// empty type otherwise the compiler thinks we only have provenance over
95+
// `Block_layout`.
9696
_layout: PhantomData<ffi::Block_layout>,
9797
// To get correct variance on args and return types
9898
_p: PhantomData<fn(A) -> R>,

crates/block2/src/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const GLOBAL_DESCRIPTOR: ffi::Block_descriptor_header = ffi::Block_descriptor_he
1818

1919
/// An Objective-C block that does not capture its environment.
2020
///
21-
/// This is effectively just a glorified function pointer, and can created and
21+
/// This is effectively a glorified function pointer, and can created and
2222
/// stored in static memory using the [`global_block!`] macro.
2323
///
2424
/// If [`ConcreteBlock`] is the [`Fn`]-block equivalent, this is likewise the

crates/block2/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! # Apple's C language extension of blocks
22
//!
3-
//! C Blocks are effectively the C-equivalent of Rust's closures, in that they
4-
//! have the ability to capture their environments.
3+
//! C Blocks are the C-equivalent of Rust's closures, in that they have the
4+
//! ability to capture their environments.
55
//!
66
//! This crate provides capabilities to create and invoke these blocks, in an
77
//! ergonomic "Rust-centric" fashion.

crates/header-translator/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cargo run --bin header-translator
1111

1212
Make sure you have the same XCode version installed as the one documented in [`crates/icrate/README.md`](../icrate/README.md).
1313

14-
If you use a different operating system than macOS, or simply have multiple SDKs installed, you can specify the directory as the first argument:
14+
If you use a different operating system than macOS, or have multiple SDKs installed, you can specify the directory as the first argument:
1515

1616
```console
1717
cargo run --bin header-translator -- /Applications/Xcode_new.app/Contents/Developer

crates/header-translator/src/data/CoreAnimation.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ data! {
4848
// `nil` superlayer.
4949

5050
// If the layer already has a superlayer, it will be changed
51-
// appropriately by these methods (effectively, removeFromSuperlayer
52-
// is called on the given layer inside these).
51+
// appropriately by these methods (`removeFromSuperlayer` is called on
52+
// the given layer inside these).
5353
unsafe -addSublayer;
5454
unsafe -insertSublayer_atIndex;
5555
unsafe -insertSublayer_below;
@@ -193,8 +193,7 @@ data! {
193193
unsafe -endFrame;
194194
}
195195

196-
// SAFETY: CATransaction is basically just a way to call methods that
197-
// access thread-local state.
196+
// SAFETY: CATransaction methods access thread-local state.
198197
class CATransaction {
199198
unsafe +begin;
200199
unsafe +commit;

crates/header-translator/src/method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl MemoryManagement {
170170
// And if:
171171
// > its signature obeys the added restrictions of the method family.
172172
//
173-
// Which is just:
173+
// Which is:
174174
// > must return a retainable object pointer
175175
if result_type.is_id() {
176176
// We also check that the correct modifier flags were set for the

crates/header-translator/src/rust_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl AttributeParser<'_, '_> {
9090
if position.strip(self.expected_name, needle).is_some() {
9191
let rest = rest.trim();
9292
// If it can be stripped from both `name` and `expected_name`,
93-
// it might just appear twice in `name`.
93+
// it might appear twice in `name`.
9494
//
9595
// This is done to support:
9696
// "const char * _Nonnull _Nonnull[]".

crates/header-translator/src/stmt.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,8 @@ impl fmt::Display for Stmt {
14671467
// Copying collections is done as a shallow copy:
14681468
// <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Articles/Copying.html>
14691469
//
1470-
// E.g. it simply does a retain count bump, and hence
1471-
// does not require the inner type to implement
1470+
// E.g. it does a retain count bump on the items, and
1471+
// hence does not require the inner type to implement
14721472
// `NSCopying`.
14731473
//
14741474
// The types does have to be cloneable, since generic
@@ -1712,8 +1712,7 @@ impl fmt::Display for Stmt {
17121712
writeln!(f, "typed_extensible_enum!(pub type {} = {ty};);", id.name)?;
17131713
}
17141714
None | Some(UnexposedAttr::BridgedTypedef) => {
1715-
// "bridged" typedefs should just use a normal type
1716-
// alias.
1715+
// "bridged" typedefs should use a normal type alias.
17171716
writeln!(f, "pub type {} = {ty};", id.name)?;
17181717
}
17191718
kind => panic!("invalid alias kind {kind:?} for {ty:?}"),

crates/header-translator/translation-config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ ios = "16.0"
421421
### - `ns_returns_retained` / `cf_returns_retained` / `os_returns_retained`
422422
###
423423
### The rest are only very rarely used in Apple's frameworks, so while we
424-
### _could_ handle them too, I think it's easier to just do it manually.
424+
### _could_ handle them too, I think it's easier to do it manually.
425425
###
426426
### See https://clang.llvm.org/docs/AttributeReference.html
427427
###
@@ -783,7 +783,7 @@ skipped = true
783783
skipped = true
784784

785785
# The original superclass typedef is a bit difficult to extract from the
786-
# superclass name, so let's just overwrite it.
786+
# superclass name, so let's do it manually.
787787
[class.ASCredentialProviderViewController]
788788
definition-skipped = true
789789
[class.ASAccountAuthenticationModificationViewController]

crates/icrate/CHANGELOG.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
269269
* Added `NSTimeInterval`.
270270
* Added `NSString::len_utf16` and `NSAttributedString::len_utf16`.
271271
* Added `NSString::concat` and `NSString::join_path`.
272-
* Added `CGSize`, `CGPoint` and `CGRect` (just aliases to equivalent
273-
`NS`-types, but helps readability).
272+
* Added `CGSize`, `CGPoint` and `CGRect` (aliases to equivalent `NS`-types
273+
that helps readability).
274274

275275
### Changed
276276
* **BREAKING**: `NSSize::new` no longer requires it's arguments to be
@@ -310,8 +310,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
310310

311311
### Removed
312312
* `NSObject::hash_code`, `NSObject::is_equal` and `NSObject::description` in
313-
favour of just having the trait implementations `Hash`, `PartiqalEq` and
314-
`Debug`.
313+
favour of having the trait implementations `Hash`, `PartiqalEq` and `Debug`.
315314

316315

317316
## objc2-foundation 0.2.0-alpha.6 - 2022-07-19
@@ -397,7 +396,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
397396
### Removed
398397
* **BREAKING**: Removed `Deref` and `DerefMut` from `NSData` and
399398
`NSMutableData`, since these invoke a non-trivial amount of code, and could
400-
easily lead to hard-to-diagnose performance issues.
399+
lead to hard-to-diagnose performance issues.
401400

402401

403402
## objc2-foundation 0.2.0-alpha.3 - 2021-12-22

crates/icrate/examples/basic_usage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
autoreleasepool(|pool| {
3232
println!("{}", string.as_str(pool));
3333
});
34-
// Or simply use the `Display` implementation
34+
// Or use the `Display` implementation
3535
let _s = string.to_string(); // Using ToString
3636
println!("{string}"); // Or Display directly
3737

crates/icrate/examples/nspasteboard.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use objc2::rc::Id;
99
use objc2::runtime::{Class, Object, ProtocolObject};
1010
use objc2::ClassType;
1111

12-
/// Simple, straightforward implementation
12+
/// Simplest implementation
1313
pub fn get_text_1(pasteboard: &NSPasteboard) -> Option<Id<NSString>> {
1414
unsafe { pasteboard.stringForType(NSPasteboardTypeString) }
1515
}

crates/icrate/src/Foundation/__macro_helpers/cached.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ impl<T: Message> CachedId<T> {
2828
let ptr = self.ptr.load(Ordering::SeqCst);
2929
// SAFETY: The pointer is either NULL, or has been created below.
3030
unsafe { ptr.as_ref() }.unwrap_or_else(|| {
31-
// "Forget" about releasing the object, effectively promoting it
32-
// to a static.
31+
// "Forget" about releasing the object, promoting it to a static.
3332
let s = ManuallyDrop::new(f());
3433
let ptr = Id::as_ptr(&s);
3534
self.ptr.store(ptr as *mut T, Ordering::SeqCst);

crates/icrate/src/Foundation/__macro_helpers/ns_string.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(feature = "Foundation_NSString")]
22
//! Macro for making a static NSString.
33
//!
4-
//! This basically does what clang does, see:
4+
//! This closely follows what clang does, see:
55
//! - Apple: <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CodeGenModule.cpp#L5057-L5249>
66
//! - GNUStep 2.0 (not yet supported): <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCGNU.cpp#L973-L1118>
77
//! - Other (not yet supported): <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCGNU.cpp#L2471-L2507>
@@ -39,8 +39,8 @@ extern "C" {
3939
#[repr(C)]
4040
pub struct CFConstString {
4141
isa: &'static Class,
42-
// Important that we don't just use `usize` here, since that would be
43-
// wrong on big-endian systems!
42+
// Important that we don't use `usize` here, since that would be wrong on
43+
// big-endian systems!
4444
cfinfo: u32,
4545
#[cfg(target_pointer_width = "64")]
4646
_rc: u32,

crates/icrate/src/Foundation/additions/data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl NSData {
3636
// bug; it forgets to assign the input buffer and length to the
3737
// instance before it swizzles to NSDataWithDeallocatorBlock.
3838
// See https://github.com/gnustep/libs-base/pull/213
39-
// So we just use NSDataWithDeallocatorBlock directly.
39+
// So instead we use NSDataWithDeallocatorBlock directly.
4040
//
4141
// NSMutableData does not have this problem.
4242
#[cfg(feature = "gnustep-1-7")]
@@ -112,7 +112,7 @@ impl NSMutableData {
112112
#[doc(alias = "replaceBytesInRange:withBytes:length:")]
113113
pub fn replace_range(&mut self, range: Range<usize>, bytes: &[u8]) {
114114
// No need to verify the length of the range here,
115-
// `replaceBytesInRange:` just zero-fills if out of bounds.
115+
// `replaceBytesInRange:` zero-fills if out of bounds.
116116
let ptr = bytes.as_ptr() as *mut c_void;
117117
unsafe { self.replaceBytesInRange_withBytes_length(range.into(), ptr, bytes.len()) }
118118
}

crates/icrate/src/Foundation/additions/dictionary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ unsafe impl<K: Message, V: Message> iter::FastEnumerationHelper for NSDictionary
345345

346346
#[cfg(feature = "Foundation_NSMutableDictionary")]
347347
unsafe impl<K: Message, V: Message> iter::FastEnumerationHelper for NSMutableDictionary<K, V> {
348-
// Naturally, the same goes for mutable dictionaries.
348+
// The same goes for mutable dictionaries.
349349
type Item = K;
350350

351351
#[inline]

crates/icrate/src/Foundation/additions/geometry.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type InnerFloat = f32;
1818
// TODO: Use a newtype here?
1919
pub type CGFloat = InnerFloat;
2020

21-
// NSGeometry types are just aliases to CGGeometry types on iOS, tvOS, watchOS
22-
// and macOS 64bit (and hence their Objective-C encodings are different).
21+
// NSGeometry types are aliases to CGGeometry types on iOS, tvOS, watchOS and
22+
// macOS 64bit (and hence their Objective-C encodings are different).
2323
//
2424
// TODO: Adjust `objc2-encode` so that this is handled there, and so that we
25-
// can effectively just forget about it and use `NS` and `CG` types equally.
25+
// can effectively forget about it and use `NS` and `CG` types equally.
2626
#[cfg(all(
2727
feature = "apple",
2828
not(all(target_os = "macos", target_pointer_width = "32"))
@@ -346,23 +346,23 @@ impl CGRect {
346346

347347
/// A point in a Cartesian coordinate system.
348348
///
349-
/// This is just a convenience alias for [`CGPoint`]. For ease of use, it is
349+
/// This is a convenience alias for [`CGPoint`]. For ease of use, it is
350350
/// available on all platforms, though in practice it is only useful on macOS.
351351
///
352352
/// See [Apple's documentation](https://developer.apple.com/documentation/foundation/nspoint?language=objc).
353353
pub type NSPoint = CGPoint;
354354

355355
/// A two-dimensional size.
356356
///
357-
/// This is just a convenience alias for [`CGSize`]. For ease of use, it is
357+
/// This is a convenience alias for [`CGSize`]. For ease of use, it is
358358
/// available on all platforms, though in practice it is only useful on macOS.
359359
///
360360
/// See [Apple's documentation](https://developer.apple.com/documentation/foundation/nssize?language=objc).
361361
pub type NSSize = CGSize;
362362

363363
/// A rectangle.
364364
///
365-
/// This is just a convenience alias for [`CGRect`]. For ease of use, it is
365+
/// This is a convenience alias for [`CGRect`]. For ease of use, it is
366366
/// available on all platforms, though in practice it is only useful on macOS.
367367
///
368368
/// See [Apple's documentation](https://developer.apple.com/documentation/foundation/nsrect?language=objc).
@@ -406,7 +406,7 @@ mod tests {
406406
use crate::Foundation::{NSEqualPoints, NSEqualRects, NSEqualSizes};
407407

408408
// We assume that comparisons handle e.g. `x` and `y` in the same way,
409-
// therefore we just set the coordinates / dimensions to the same.
409+
// therefore we set the coordinates / dimensions to the same.
410410
let cases: &[(CGFloat, CGFloat)] = &[
411411
(0.0, 0.0),
412412
(-0.0, -0.0),

crates/icrate/src/Foundation/additions/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl FastEnumeratorHelper {
174174
// violated, but if that is the case, the program already
175175
// has UB, so then it is better that we detect it.
176176
//
177-
// - The value is a simple integer, so is always initialized.
177+
// - The value is an integer, so is always initialized.
178178
//
179179
//
180180
// We do an unaligned read here since we have no guarantees

crates/icrate/src/Foundation/additions/number.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use objc2::encode::Encoding;
2020
use crate::common::*;
2121
use crate::Foundation::{CGFloat, NSNumber};
2222

23-
// SAFETY: `NSNumber` is just a wrapper around an integer/float/bool, and it
24-
// is immutable.
23+
// SAFETY: `NSNumber` is a wrapper around an integer/float/bool, and it is
24+
// immutable.
2525
unsafe impl Sync for NSNumber {}
2626
unsafe impl Send for NSNumber {}
2727

0 commit comments

Comments
 (0)