servo/cocoa-rs

Automatic string conversion for NSString::init_str

Closed this issue · 1 comments

It's a bit of a pain manually adding the C-style null-terminator to every slice that's passed into appkit::NSString::init_str. Can we take a cue from base::class and do this?

use std::ffi;

unsafe fn init_str(self, string: &str) -> id {
    let c_string = ffi::CString::from_slice(string.as_bytes());
    self.initWithUTF8String_(c_string.as_ptr())
}

I made this change yesterday for an unrelated bug without realising this issue was here.