Skip to content

Commit a004f56

Browse files
committed
NSValue returns an Encoding, not just a str.
1 parent 4b602cb commit a004f56

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/value.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44
use std::str;
55
use libc::c_char;
66

7-
use objc::Encode;
7+
use objc::{Encode, Encoding};
88
use objc::runtime::Class;
99
use objc_id::Id;
1010

@@ -14,19 +14,20 @@ pub trait INSValue : INSObject {
1414
type Value: 'static + Copy + Encode;
1515

1616
fn value(&self) -> Self::Value {
17-
assert!(Self::Value::encode().as_str() == self.encoding());
17+
assert!(Self::Value::encode() == self.encoding());
1818
unsafe {
1919
let mut value = mem::uninitialized::<Self::Value>();
2020
let _: () = msg_send![self, getValue:&mut value];
2121
value
2222
}
2323
}
2424

25-
fn encoding(&self) -> &str {
25+
fn encoding(&self) -> Encoding {
2626
unsafe {
2727
let result: *const c_char = msg_send![self, objCType];
2828
let s = CStr::from_ptr(result);
29-
str::from_utf8(s.to_bytes()).unwrap()
29+
let s = str::from_utf8(s.to_bytes()).unwrap();
30+
Encoding::from_str(s)
3031
}
3132
}
3233

@@ -71,6 +72,6 @@ mod tests {
7172
fn test_value() {
7273
let val = NSValue::from_value(13u32);
7374
assert!(val.value() == 13);
74-
assert!(u32::encode().as_str() == val.encoding());
75+
assert!(u32::encode() == val.encoding());
7576
}
7677
}

0 commit comments

Comments
 (0)