Skip to content

Commit

Permalink
Use static encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 9, 2022
1 parent 78a6b51 commit bb0e66b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions objc2/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ mod ivar;
mod ivar_forwarding_impls;

use alloc::format;
use alloc::string::ToString;
use core::mem;
use core::mem::ManuallyDrop;
use core::ptr;
Expand Down Expand Up @@ -409,7 +408,7 @@ impl ClassBuilder {
/// happens if there already was an ivar with that name.
pub fn add_ivar<T: Encode>(&mut self, name: &str) {
let c_name = CString::new(name).unwrap();
let encoding = CString::new(T::ENCODING.to_string()).unwrap();
let encoding = T::ENCODING_CSTR;
let size = mem::size_of::<T>();
let align = log2_align_of::<T>();
let success = Bool::from_raw(unsafe {
Expand Down
5 changes: 2 additions & 3 deletions objc2/src/foundation/value.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use alloc::string::ToString;
use core::ffi::c_void;
use core::fmt;
use core::hash;
use core::mem::MaybeUninit;
use core::ptr::NonNull;
use core::str;
use std::ffi::{CStr, CString};
use std::ffi::CStr;
use std::os::raw::c_char;

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

0 comments on commit bb0e66b

Please sign in to comment.