Skip to content

Commit e0deb58

Browse files
committed
Feature-gate block support in objc_foundation
1 parent e62ea58 commit e0deb58

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ jobs:
113113
uses: actions-rs/cargo@v1
114114
with:
115115
command: test
116-
args: --verbose --no-fail-fast
116+
# TODO: `objc/exception` feature is broken in objc_foundation
117+
# TODO: `objc_foundation/block` feature doesn't work on GNUStep
118+
args: --verbose --no-fail-fast --no-default-features

objc_foundation/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ license = "MIT"
1212

1313
exclude = [".gitignore"]
1414

15+
[features]
16+
default = ["block"]
17+
1518
[dependencies]
16-
block = "0.1"
19+
block = { optional = true, version = "0.1" }
1720
objc = { path = "../objc", version = "0.2.7" }
1821
objc_id = { path = "../objc_id", version = "0.1" }

objc_foundation/src/data.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::mem;
21
use std::ops::Range;
32
use std::os::raw::c_void;
43
use std::slice;
54

65
use super::{INSCopying, INSMutableCopying, INSObject, NSRange};
6+
#[cfg(feature = "block")]
77
use block::{Block, ConcreteBlock};
88
use objc::msg_send;
99
use objc_id::Id;
@@ -39,6 +39,7 @@ pub trait INSData: INSObject {
3939
}
4040
}
4141

42+
#[cfg(feature = "block")]
4243
fn from_vec(bytes: Vec<u8>) -> Id<Self> {
4344
let capacity = bytes.capacity();
4445
let dealloc = ConcreteBlock::new(move |bytes: *mut c_void, len: usize| unsafe {
@@ -56,7 +57,7 @@ pub trait INSData: INSObject {
5657
let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes_ptr
5758
length:bytes.len()
5859
deallocator:dealloc];
59-
mem::forget(bytes);
60+
std::mem::forget(bytes);
6061
Id::from_retained_ptr(obj)
6162
}
6263
}
@@ -192,6 +193,7 @@ mod tests {
192193
assert!(data.bytes() == [8, 17]);
193194
}
194195

196+
#[cfg(feature = "block")]
195197
#[test]
196198
fn test_from_vec() {
197199
let bytes = vec![3, 7, 16];

0 commit comments

Comments
 (0)