Skip to content

Commit 677ef61

Browse files
committed
Implement RefEncode for Protocol
1 parent ae70554 commit 677ef61

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

objc2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
* Export `objc-sys` as `ffi` module.
1111
* Added common trait impls on `rc::Owned` and `rc::Shared` (useful in generic
1212
contexts).
13+
* Implement `RefEncode` for `runtime::Protocol`.
1314

1415
### Changed
1516
* Deprecated `runtime::BOOL`, `runtime::YES` and `runtime::NO`. Use the

objc2/src/runtime.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ impl PartialEq for Protocol {
472472
}
473473
}
474474

475+
unsafe impl RefEncode for Protocol {
476+
// Protocol is an object internally
477+
const ENCODING_REF: Encoding<'static> = Encoding::Object;
478+
}
479+
475480
impl Eq for Protocol {}
476481

477482
impl fmt::Debug for Protocol {
@@ -697,12 +702,16 @@ mod tests {
697702

698703
#[test]
699704
fn test_encode() {
700-
assert_eq!(<&Object>::ENCODING.to_string(), "@");
701-
assert_eq!(<*mut Object>::ENCODING.to_string(), "@");
702-
assert_eq!(<&Class>::ENCODING.to_string(), "#");
703-
assert_eq!(Sel::ENCODING.to_string(), ":");
704-
assert_eq!(Imp::ENCODING.to_string(), "^?");
705-
assert_eq!(<Option<Imp>>::ENCODING.to_string(), "^?");
705+
fn assert_enc<T: Encode>(expected: &str) {
706+
assert_eq!(&T::ENCODING.to_string(), expected);
707+
}
708+
assert_enc::<&Object>("@");
709+
assert_enc::<*mut Object>("@");
710+
assert_enc::<&Class>("#");
711+
assert_enc::<Sel>(":");
712+
assert_enc::<Imp>("^?");
713+
assert_enc::<Option<Imp>>("^?");
714+
assert_enc::<&Protocol>("@");
706715
}
707716

708717
#[test]

0 commit comments

Comments
 (0)