Skip to content

Commit fdce3e9

Browse files
committed
Use static encoding
1 parent c5ad3ce commit fdce3e9

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

objc2/src/declare.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ mod ivar;
115115
mod ivar_forwarding_impls;
116116

117117
use alloc::format;
118-
use alloc::string::ToString;
119118
use core::mem;
120119
use core::mem::ManuallyDrop;
121120
use core::ptr;
@@ -409,7 +408,7 @@ impl ClassBuilder {
409408
/// happens if there already was an ivar with that name.
410409
pub fn add_ivar<T: Encode>(&mut self, name: &str) {
411410
let c_name = CString::new(name).unwrap();
412-
let encoding = CString::new(T::ENCODING.to_string()).unwrap();
411+
let encoding = T::ENCODING_CSTR;
413412
let size = mem::size_of::<T>();
414413
let align = log2_align_of::<T>();
415414
let success = Bool::from_raw(unsafe {

objc2/src/foundation/value.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use alloc::string::ToString;
21
use core::ffi::c_void;
32
use core::fmt;
43
use core::hash;
54
use core::mem::MaybeUninit;
65
use core::ptr::NonNull;
76
use core::str;
8-
use std::ffi::{CStr, CString};
7+
use std::ffi::CStr;
98
use std::os::raw::c_char;
109

1110
use super::{NSCopying, NSObject, NSPoint, NSRange, NSRect, NSSize};
@@ -65,7 +64,7 @@ impl NSValue {
6564
pub fn new<T: 'static + Copy + Encode>(value: T) -> Id<Self, Shared> {
6665
let bytes: *const T = &value;
6766
let bytes: *const c_void = bytes.cast();
68-
let encoding = CString::new(T::ENCODING.to_string()).unwrap();
67+
let encoding = T::ENCODING_CSTR;
6968
unsafe {
7069
msg_send_id![
7170
msg_send_id![Self::class(), alloc],

0 commit comments

Comments
 (0)