From 4b64b69e900e3eae5c410055c4c03a59c45419c2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 25 Aug 2018 04:40:04 +0200 Subject: run_key_action(): Include action string for `MapKind::Map` Couldn't figure out how to make my `Action` string a char slice. At first I changed it to a `CStr` reference, but ran into lifetime errors when trying to use a reference. Instead ended up making it a `CString`. Still need to handle errors. My plan is to pass back an error string in the result struct. Remains to be seen whether this actually works when calling it over FFI, but we have the beginnings of something. --- src/cocoa_bridge.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 2773f11..df144f1 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use cocoa::base::nil; use cocoa::foundation::{NSArray, NSAutoreleasePool, NSDictionary}; @@ -37,8 +39,8 @@ map j"; // Somehow: switch mode inside Rust #[repr(C)] -pub struct KeyActionResult<'a> { - pub action: Option<&'a [char]>, +pub struct KeyActionResult { + pub action: Option, pub kind: MapKind, } @@ -57,8 +59,13 @@ map j"; if let Some(map) = map { return match map.kind { MapKind::Map => { + // let action_bytes = map.action; + // let x = action_bytes.as_bytes(); + // let action = CStr::from_bytes_with_nul(x).unwrap(); + let action = CString::new(map.action.clone()).unwrap(); + Some(KeyActionResult { - action: None, //Some(m.action.as_str()), + action: Some(action), kind: MapKind::Map, }) }, -- cgit v1.2.3