diff options
| author | Teddy Wing | 2018-08-25 04:40:04 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-08-25 04:40:04 +0200 | 
| commit | 4b64b69e900e3eae5c410055c4c03a59c45419c2 (patch) | |
| tree | bb23dfbc43c4c9ae047f8c3d4d750f04372f6d2b | |
| parent | a5c41687a3a294bdd8b000d416ab1787a5c40d2c (diff) | |
| download | dome-key-map-4b64b69e900e3eae5c410055c4c03a59c45419c2.tar.bz2 | |
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.
| -rw-r--r-- | src/cocoa_bridge.rs | 13 | 
1 files changed, 10 insertions, 3 deletions
| 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 <down> j";  // Somehow: switch mode inside Rust  #[repr(C)] -pub struct KeyActionResult<'a> { -    pub action: Option<&'a [char]>, +pub struct KeyActionResult { +    pub action: Option<CString>,      pub kind: MapKind,  } @@ -57,8 +59,13 @@ map <down> 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,                  })              }, | 
