Skip to content

Commit 2e5fa2d

Browse files
committed
Remove lifetime specifier from Encoding
1 parent e8dec22 commit 2e5fa2d

33 files changed

+117
-121
lines changed

block2/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub struct Block<A, R> {
9494
}
9595

9696
unsafe impl<A: BlockArguments, R: Encode> RefEncode for Block<A, R> {
97-
const ENCODING_REF: Encoding<'static> = Encoding::Block;
97+
const ENCODING_REF: Encoding = Encoding::Block;
9898
}
9999

100100
impl<A: BlockArguments, R: Encode> Block<A, R> {

block2/src/concrete_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub struct ConcreteBlock<A, R, F> {
167167
}
168168

169169
unsafe impl<A: BlockArguments, R: Encode, F> RefEncode for ConcreteBlock<A, R, F> {
170-
const ENCODING_REF: Encoding<'static> = Encoding::Block;
170+
const ENCODING_REF: Encoding = Encoding::Block;
171171
}
172172

173173
impl<A, R, F> ConcreteBlock<A, R, F>

objc2-encode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased - YYYY-MM-DD
88

9+
### Changed
10+
* **BREAKING**: Remove the lifetime specifier from `Encoding`, since the non
11+
-`'static` version was essentially useless.
12+
913
### Fixed
1014
* Fixed the encoding output and comparison of structs behind pointers.
1115

objc2-encode/examples/core_graphics.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ struct CGPoint {
1313
}
1414

1515
unsafe impl Encode for CGPoint {
16-
const ENCODING: Encoding<'static> =
17-
Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]);
16+
const ENCODING: Encoding = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]);
1817
}
1918

2019
#[repr(C)]
@@ -24,8 +23,7 @@ struct CGSize {
2423
}
2524

2625
unsafe impl Encode for CGSize {
27-
const ENCODING: Encoding<'static> =
28-
Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]);
26+
const ENCODING: Encoding = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]);
2927
}
3028

3129
#[repr(C)]
@@ -35,8 +33,7 @@ struct CGRect {
3533
}
3634

3735
unsafe impl Encode for CGRect {
38-
const ENCODING: Encoding<'static> =
39-
Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]);
36+
const ENCODING: Encoding = Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]);
4037
}
4138

4239
fn main() {

objc2-encode/examples/ns_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct NSString {
1212

1313
/// Implement `RefEncode` for pointers and references to the string.
1414
unsafe impl RefEncode for NSString {
15-
const ENCODING_REF: Encoding<'static> = Encoding::Object;
15+
const ENCODING_REF: Encoding = Encoding::Object;
1616
}
1717

1818
fn main() {

objc2-encode/examples/ns_uinteger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ unsafe impl Encode for NSUInteger {
1414
/// Running `@encode(NSUInteger)` gives `Q` on 64-bit systems and `I` on
1515
/// 32-bit systems. This corresponds exactly to `usize`, which is also how
1616
/// we've defined our struct.
17-
const ENCODING: Encoding<'static> = usize::ENCODING;
17+
const ENCODING: Encoding = usize::ENCODING;
1818
}
1919

2020
// SAFETY: `&NSUInteger` has the same representation as `&usize`.
2121
unsafe impl RefEncode for NSUInteger {
2222
/// Running `@encode(NSUInteger*)` gives `^Q` on 64-bit systems and `^I`
2323
/// on 32-bit systems. So implementing `RefEncode` as a plain pointer is
2424
/// correct.
25-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&NSUInteger::ENCODING);
25+
const ENCODING_REF: Encoding = Encoding::Pointer(&NSUInteger::ENCODING);
2626
}
2727

2828
fn main() {

objc2-encode/examples/opaque_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct NSDecimal {
1515
// SAFETY: `&NSDecimal` is a pointer.
1616
unsafe impl RefEncode for NSDecimal {
1717
// Running `@encode` on `NSDecimal*` on my 64-bit system gives `^{?=cCCC[38C]}`.
18-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Encoding::Struct(
18+
const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct(
1919
"?",
2020
&[
2121
Encoding::Char,

objc2-encode/src/encode.rs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use crate::Encoding;
4949
/// }
5050
///
5151
/// unsafe impl Encode for MyType {
52-
/// const ENCODING: Encoding<'static> = Encoding::Struct(
52+
/// const ENCODING: Encoding = Encoding::Struct(
5353
/// // The name of the type that Objective-C sees.
5454
/// "MyType",
5555
/// &[
@@ -68,7 +68,7 @@ use crate::Encoding;
6868
/// [reprs]: https://doc.rust-lang.org/nomicon/other-reprs.html
6969
pub unsafe trait Encode {
7070
/// The Objective-C type-encoding for this type.
71-
const ENCODING: Encoding<'static>;
71+
const ENCODING: Encoding;
7272
}
7373

7474
/// Types whoose references has an Objective-C type-encoding.
@@ -127,7 +127,7 @@ pub unsafe trait RefEncode {
127127
/// # _priv: [u8; 0],
128128
/// # }
129129
/// # unsafe impl RefEncode for MyObject {
130-
/// const ENCODING_REF: Encoding<'static> = Encoding::Object;
130+
/// const ENCODING_REF: Encoding = Encoding::Object;
131131
/// # }
132132
/// ```
133133
///
@@ -138,13 +138,13 @@ pub unsafe trait RefEncode {
138138
/// # #[repr(transparent)]
139139
/// # struct MyType(i32);
140140
/// # unsafe impl Encode for MyType {
141-
/// # const ENCODING: Encoding<'static> = i32::ENCODING;
141+
/// # const ENCODING: Encoding = i32::ENCODING;
142142
/// # }
143143
/// # unsafe impl RefEncode for MyType {
144-
/// const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
144+
/// const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
145145
/// # }
146146
/// ```
147-
const ENCODING_REF: Encoding<'static>;
147+
const ENCODING_REF: Encoding;
148148
}
149149

150150
// TODO: Implement for `PhantomData` and `PhantomPinned`?
@@ -153,7 +153,7 @@ pub unsafe trait RefEncode {
153153
macro_rules! encode_impls {
154154
($($t:ty => $e:ident,)*) => ($(
155155
unsafe impl Encode for $t {
156-
const ENCODING: Encoding<'static> = Encoding::$e;
156+
const ENCODING: Encoding = Encoding::$e;
157157
}
158158
)*);
159159
}
@@ -182,7 +182,7 @@ encode_impls!(
182182
/// `()` is not FFI-safe)!
183183
// TODO: Figure out a way to remove this - maybe with a `EncodeReturn` trait?
184184
unsafe impl Encode for () {
185-
const ENCODING: Encoding<'static> = Encoding::Void;
185+
const ENCODING: Encoding = Encoding::Void;
186186
}
187187

188188
// UI tests of this is too brittle.
@@ -212,19 +212,19 @@ extern "C" {}
212212
///
213213
/// Use `objc2::runtime::Bool::ENCODING` instead.
214214
unsafe impl Encode for bool {
215-
const ENCODING: Encoding<'static> = Encoding::Bool;
215+
const ENCODING: Encoding = Encoding::Bool;
216216
}
217217

218218
macro_rules! encode_impls_size {
219219
($($t:ty => ($t16:ty, $t32:ty, $t64:ty),)*) => ($(
220220
#[doc = concat!("The encoding of [`", stringify!($t), "`] varies based on the target pointer width.")]
221221
unsafe impl Encode for $t {
222222
#[cfg(target_pointer_width = "16")]
223-
const ENCODING: Encoding<'static> = <$t16>::ENCODING;
223+
const ENCODING: Encoding = <$t16>::ENCODING;
224224
#[cfg(target_pointer_width = "32")]
225-
const ENCODING: Encoding<'static> = <$t32>::ENCODING;
225+
const ENCODING: Encoding = <$t32>::ENCODING;
226226
#[cfg(target_pointer_width = "64")]
227-
const ENCODING: Encoding<'static> = <$t64>::ENCODING;
227+
const ENCODING: Encoding = <$t64>::ENCODING;
228228
}
229229
)*);
230230
}
@@ -238,7 +238,7 @@ encode_impls_size!(
238238
macro_rules! pointer_refencode_impl {
239239
($($t:ty),*) => ($(
240240
unsafe impl RefEncode for $t {
241-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
241+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
242242
}
243243
)*);
244244
}
@@ -247,31 +247,31 @@ pointer_refencode_impl!(bool, i16, i32, i64, isize, u16, u32, u64, usize, f32, f
247247

248248
/// Pointers to [`i8`] use the special [`Encoding::String`] encoding.
249249
unsafe impl RefEncode for i8 {
250-
const ENCODING_REF: Encoding<'static> = Encoding::String;
250+
const ENCODING_REF: Encoding = Encoding::String;
251251
}
252252

253253
/// Pointers to [`u8`] use the special [`Encoding::String`] encoding.
254254
unsafe impl RefEncode for u8 {
255-
const ENCODING_REF: Encoding<'static> = Encoding::String;
255+
const ENCODING_REF: Encoding = Encoding::String;
256256
}
257257

258258
/// Simple helper for implementing [`Encode`] for nonzero integer types.
259259
macro_rules! encode_impls_nonzero {
260260
($($nonzero:ident => $type:ty,)*) => ($(
261261
unsafe impl Encode for $nonzero {
262-
const ENCODING: Encoding<'static> = <$type>::ENCODING;
262+
const ENCODING: Encoding = <$type>::ENCODING;
263263
}
264264

265265
unsafe impl Encode for Option<$nonzero> {
266-
const ENCODING: Encoding<'static> = <$type>::ENCODING;
266+
const ENCODING: Encoding = <$type>::ENCODING;
267267
}
268268

269269
unsafe impl RefEncode for $nonzero {
270-
const ENCODING_REF: Encoding<'static> = <$type>::ENCODING_REF;
270+
const ENCODING_REF: Encoding = <$type>::ENCODING_REF;
271271
}
272272

273273
unsafe impl RefEncode for Option<$nonzero> {
274-
const ENCODING_REF: Encoding<'static> = <$type>::ENCODING_REF;
274+
const ENCODING_REF: Encoding = <$type>::ENCODING_REF;
275275
}
276276
)*);
277277
}
@@ -300,12 +300,12 @@ macro_rules! encode_atomic_impls {
300300
// in-memory representation as the underlying type.
301301
$(#[$m])*
302302
unsafe impl Encode for atomic::$atomic {
303-
const ENCODING: Encoding<'static> = Encoding::Atomic(&<$type>::ENCODING);
303+
const ENCODING: Encoding = Encoding::Atomic(&<$type>::ENCODING);
304304
}
305305

306306
$(#[$m])*
307307
unsafe impl RefEncode for atomic::$atomic {
308-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
308+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
309309
}
310310
)*);
311311
}
@@ -348,50 +348,50 @@ encode_atomic_impls!(
348348
// SAFETY: Guaranteed to have the same in-memory representation as `*mut T`.
349349
#[cfg(target_has_atomic = "ptr")]
350350
unsafe impl<T: RefEncode> Encode for atomic::AtomicPtr<T> {
351-
const ENCODING: Encoding<'static> = Encoding::Atomic(&T::ENCODING_REF);
351+
const ENCODING: Encoding = Encoding::Atomic(&T::ENCODING_REF);
352352
}
353353

354354
#[cfg(target_has_atomic = "ptr")]
355355
unsafe impl<T: RefEncode> RefEncode for atomic::AtomicPtr<T> {
356-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
356+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
357357
}
358358

359359
/// [`Encode`] is implemented manually for `*const c_void`, instead of
360360
/// implementing [`RefEncode`], to discourage creating `&c_void`.
361361
unsafe impl Encode for *const c_void {
362-
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
362+
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Void);
363363
}
364364

365365
unsafe impl RefEncode for *const c_void {
366-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
366+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
367367
}
368368

369369
/// [`Encode`] is implemented manually for `*mut c_void`, instead of
370370
/// implementing [`RefEncode`], to discourage creating `&mut c_void`.
371371
unsafe impl Encode for *mut c_void {
372-
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
372+
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Void);
373373
}
374374

375375
unsafe impl RefEncode for *mut c_void {
376-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
376+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
377377
}
378378

379379
unsafe impl<T: Encode, const LENGTH: usize> Encode for [T; LENGTH] {
380-
const ENCODING: Encoding<'static> = Encoding::Array(LENGTH, &T::ENCODING);
380+
const ENCODING: Encoding = Encoding::Array(LENGTH, &T::ENCODING);
381381
}
382382

383383
unsafe impl<T: Encode, const LENGTH: usize> RefEncode for [T; LENGTH] {
384-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
384+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
385385
}
386386

387387
macro_rules! encode_impls_transparent {
388388
($($t:ident<T $(: ?$b:ident)?>,)*) => ($(
389389
unsafe impl<T: Encode $(+ ?$b)?> Encode for $t<T> {
390-
const ENCODING: Encoding<'static> = T::ENCODING;
390+
const ENCODING: Encoding = T::ENCODING;
391391
}
392392

393393
unsafe impl<T: RefEncode $(+ ?$b)?> RefEncode for $t<T> {
394-
const ENCODING_REF: Encoding<'static> = T::ENCODING_REF;
394+
const ENCODING_REF: Encoding = T::ENCODING_REF;
395395
}
396396
)*);
397397
}
@@ -439,35 +439,35 @@ macro_rules! encode_pointer_impls {
439439
const $c:ident = $e:expr;
440440
}) => (
441441
unsafe impl<T: RefEncode + ?Sized> $x for *const T {
442-
const $c: Encoding<'static> = $e;
442+
const $c: Encoding = $e;
443443
}
444444

445445
unsafe impl<T: RefEncode + ?Sized> $x for *mut T {
446-
const $c: Encoding<'static> = $e;
446+
const $c: Encoding = $e;
447447
}
448448

449449
unsafe impl<'a, T: RefEncode + ?Sized> $x for &'a T {
450-
const $c: Encoding<'static> = $e;
450+
const $c: Encoding = $e;
451451
}
452452

453453
unsafe impl<'a, T: RefEncode + ?Sized> $x for &'a mut T {
454-
const $c: Encoding<'static> = $e;
454+
const $c: Encoding = $e;
455455
}
456456

457457
unsafe impl<T: RefEncode + ?Sized> $x for NonNull<T> {
458-
const $c: Encoding<'static> = $e;
458+
const $c: Encoding = $e;
459459
}
460460

461461
unsafe impl<'a, T: RefEncode + ?Sized> $x for Option<&'a T> {
462-
const $c: Encoding<'static> = $e;
462+
const $c: Encoding = $e;
463463
}
464464

465465
unsafe impl<'a, T: RefEncode + ?Sized> $x for Option<&'a mut T> {
466-
const $c: Encoding<'static> = $e;
466+
const $c: Encoding = $e;
467467
}
468468

469469
unsafe impl<T: RefEncode + ?Sized> $x for Option<NonNull<T>> {
470-
const $c: Encoding<'static> = $e;
470+
const $c: Encoding = $e;
471471
}
472472
);
473473
}
@@ -510,17 +510,17 @@ encode_pointer_impls!(
510510
macro_rules! encode_fn_pointer_impl {
511511
(@ $FnTy: ty, $($Arg: ident),*) => {
512512
unsafe impl<Ret: Encode, $($Arg: Encode),*> Encode for $FnTy {
513-
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Unknown);
513+
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Unknown);
514514
}
515515
unsafe impl<Ret: Encode, $($Arg: Encode),*> RefEncode for $FnTy {
516-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
516+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
517517
}
518518

519519
unsafe impl<Ret: Encode, $($Arg: Encode),*> Encode for Option<$FnTy> {
520-
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Unknown);
520+
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Unknown);
521521
}
522522
unsafe impl<Ret: Encode, $($Arg: Encode),*> RefEncode for Option<$FnTy> {
523-
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
523+
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
524524
}
525525
};
526526
(# $abi:literal; $($Arg: ident),+) => {
@@ -576,15 +576,15 @@ mod private {
576576
/// issue if you know a use-case where this restrition should be lifted!
577577
pub unsafe trait EncodeArguments: private::Sealed {
578578
/// The encodings for the arguments.
579-
const ENCODINGS: &'static [Encoding<'static>];
579+
const ENCODINGS: &'static [Encoding];
580580
}
581581

582582
macro_rules! encode_args_impl {
583583
($($Arg: ident),*) => {
584584
impl<$($Arg: Encode),*> private::Sealed for ($($Arg,)*) {}
585585

586586
unsafe impl<$($Arg: Encode),*> EncodeArguments for ($($Arg,)*) {
587-
const ENCODINGS: &'static [Encoding<'static>] = &[
587+
const ENCODINGS: &'static [Encoding] = &[
588588
$($Arg::ENCODING),*
589589
];
590590
}

0 commit comments

Comments
 (0)