changeset 7: |
315fedf35bc7 |
parent: |
8f59e2f1b8c4
|
child: |
bebb76da449c |
author: |
ellis <ellis@rwest.io> |
date: |
Sun, 07 May 2023 18:06:13 -0400 |
permissions: |
-rw-r--r-- |
description: |
rust ffi macros, general stuff |
1 //! demo/lib.rs --- generated by DEMO:RS-MACROEXPAND 5 use obj::{Objective,Service,CustomService}; 6 use std::ffi::{CStr, CString}; 8 use libc::{c_char, size_t}; 10 pub unsafe extern "C" fn free_service(ptr: *mut Service) { 14 let _ = Box::from_raw(ptr); 17 pub unsafe extern "C" fn service_from_string(ptr: *const c_char) -> *mut Service { 18 assert!(!ptr.is_null()); 19 let p = CStr::from_ptr(ptr).to_str().unwrap(); 20 Box::into_raw(Box::new(p.into())) 23 pub unsafe extern "C" fn service_from_json_string(ptr: *const c_char) -> *mut Service { 24 assert!(!ptr.is_null()); 25 let s = CStr::from_ptr(ptr); 26 Box::into_raw(Box::new(Service::from_json_str(&s.to_str().unwrap()).unwrap())) 29 pub unsafe extern "C" fn service_to_json_string(ptr: *const Service) -> *mut c_char { 31 let x = p.to_json_string().unwrap(); 32 CString::new(x.as_str().as_bytes()).unwrap().into_raw() 35 pub unsafe extern "C" fn service_from_ron_string(ptr: *const c_char) -> *mut Service { 36 assert!(!ptr.is_null()); 37 let s = CStr::from_ptr(ptr); 38 Box::into_raw(Box::new(Service::from_ron_str(&s.to_str().unwrap()).unwrap())) 41 pub unsafe extern "C" fn service_to_ron_string(ptr: *const Service) -> *mut c_char { 43 let x = p.to_ron_string().unwrap(); 44 CString::new(x.as_str().as_bytes()).unwrap().into_raw() 47 pub unsafe extern "C" fn service_decode(ptr: *const u8, len: size_t) -> *mut Service { 48 Box::into_raw(Box::new(Service::decode(slice::from_raw_parts(ptr, len)).unwrap())) 51 pub unsafe extern "C" fn service_encode(ptr: *const Service) -> *mut u8 { 53 let mut x = p.encode().unwrap(); 54 let r = x.as_mut_ptr(); 59 pub unsafe extern "C" fn free_custom_service(ptr: *mut CustomService) { 63 let _ = Box::from_raw(ptr); 66 pub unsafe extern "C" fn custom_service_from_string( 68 ) -> *mut CustomService { 69 assert!(!ptr.is_null()); 70 let p = CStr::from_ptr(ptr).to_str().unwrap(); 71 Box::into_raw(Box::new(p.into())) 74 pub unsafe extern "C" fn custom_service_from_json_string(ptr: *const c_char) -> *mut CustomService { 75 assert!(!ptr.is_null()); 76 let s = CStr::from_ptr(ptr); 77 Box::into_raw(Box::new(CustomService::from_json_str(&s.to_str().unwrap()).unwrap()))} 79 pub unsafe extern "C" fn custom_service_to_json_string( 80 ptr: *const CustomService, 83 let x = p.to_json_string().unwrap(); 84 CString::new(x.as_str().as_bytes()).unwrap().into_raw() 87 pub unsafe extern "C" fn custom_service_from_ron_string( 89 ) -> *mut CustomService { 90 assert!(!ptr.is_null()); 91 let s = CStr::from_ptr(ptr); 92 Box::into_raw(Box::new(CustomService::from_ron_str(&s.to_str().unwrap()).unwrap())) 95 pub unsafe extern "C" fn custom_service_to_ron_string( 96 ptr: *const CustomService, 99 let x = p.to_ron_string().unwrap(); 100 CString::new(x.as_str().as_bytes()).unwrap().into_raw() 103 pub unsafe extern "C" fn custom_service_decode( 106 ) -> *mut CustomService { 108 Box::new(CustomService::decode(slice::from_raw_parts(ptr, len)).unwrap()), 112 pub unsafe extern "C" fn custom_service_encode(ptr: *const CustomService) -> *mut u8 { 114 let mut x = p.encode().unwrap(); 115 let r = x.as_mut_ptr();