changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > demo / lib.rs

changeset 11: d8f806f1d327
parent: bebb76da449c
child: a1137af05c8d
author: ellis <ellis@rwest.io>
date: Sun, 14 May 2023 21:27:04 -0400
permissions: -rw-r--r--
description: obj updates
1 //! demo/lib.rs --- generated by DEMO:RS-MACROEXPAND
2 extern crate libc;
3 extern crate obj;
4 //pub use fig::*;
5 use libc::{c_char, size_t};
6 use obj::{CustomService, Objective, Service};
7 use std::ffi::{CStr, CString};
8 use std::slice;
9 #[no_mangle]
10 pub unsafe extern "C" fn free_service(ptr: *mut Service) {
11  if ptr.is_null() {
12  return;
13  }
14  let _ = Box::from_raw(ptr);
15 }
16 #[no_mangle]
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()))
21 }
22 #[no_mangle]
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(
27  Service::from_json_str(&s.to_str().unwrap()).unwrap(),
28  ))
29 }
30 #[no_mangle]
31 pub unsafe extern "C" fn service_to_json_string(ptr: *const Service) -> *mut c_char {
32  let p = &*ptr;
33  let x = p.to_json_string().unwrap();
34  CString::new(x.as_str().as_bytes()).unwrap().into_raw()
35 }
36 #[no_mangle]
37 pub unsafe extern "C" fn service_from_ron_string(ptr: *const c_char) -> *mut Service {
38  assert!(!ptr.is_null());
39  let s = CStr::from_ptr(ptr);
40  Box::into_raw(Box::new(
41  Service::from_ron_str(&s.to_str().unwrap()).unwrap(),
42  ))
43 }
44 #[no_mangle]
45 pub unsafe extern "C" fn service_to_ron_string(ptr: *const Service) -> *mut c_char {
46  let p = &*ptr;
47  let x = p.to_ron_string().unwrap();
48  CString::new(x.as_str().as_bytes()).unwrap().into_raw()
49 }
50 #[no_mangle]
51 pub unsafe extern "C" fn service_decode(ptr: *const u8, len: size_t) -> *mut Service {
52  Box::into_raw(Box::new(
53  Service::decode(slice::from_raw_parts(ptr, len)).unwrap(),
54  ))
55 }
56 #[no_mangle]
57 pub unsafe extern "C" fn service_encode(ptr: *const Service) -> *mut u8 {
58  let p = &*ptr;
59  let mut x = p.encode().unwrap();
60  let r = x.as_mut_ptr();
61  std::mem::forget(x);
62  r
63 }
64 #[no_mangle]
65 pub unsafe extern "C" fn free_custom_service(ptr: *mut CustomService) {
66  if ptr.is_null() {
67  return;
68  }
69  let _ = Box::from_raw(ptr);
70 }
71 #[no_mangle]
72 pub unsafe extern "C" fn custom_service_from_string(ptr: *const c_char) -> *mut CustomService {
73  assert!(!ptr.is_null());
74  let p = CStr::from_ptr(ptr).to_str().unwrap();
75  Box::into_raw(Box::new(p.into()))
76 }
77 #[no_mangle]
78 pub unsafe extern "C" fn custom_service_from_json_string(ptr: *const c_char) -> *mut CustomService {
79  assert!(!ptr.is_null());
80  let s = CStr::from_ptr(ptr);
81  Box::into_raw(Box::new(
82  CustomService::from_json_str(&s.to_str().unwrap()).unwrap(),
83  ))
84 }
85 #[no_mangle]
86 pub unsafe extern "C" fn custom_service_to_json_string(ptr: *const CustomService) -> *mut c_char {
87  let p = &*ptr;
88  let x = p.to_json_string().unwrap();
89  CString::new(x.as_str().as_bytes()).unwrap().into_raw()
90 }
91 #[no_mangle]
92 pub unsafe extern "C" fn custom_service_from_ron_string(ptr: *const c_char) -> *mut CustomService {
93  assert!(!ptr.is_null());
94  let s = CStr::from_ptr(ptr);
95  Box::into_raw(Box::new(
96  CustomService::from_ron_str(&s.to_str().unwrap()).unwrap(),
97  ))
98 }
99 #[no_mangle]
100 pub unsafe extern "C" fn custom_service_to_ron_string(ptr: *const CustomService) -> *mut c_char {
101  let p = &*ptr;
102  let x = p.to_ron_string().unwrap();
103  CString::new(x.as_str().as_bytes()).unwrap().into_raw()
104 }
105 #[no_mangle]
106 pub unsafe extern "C" fn custom_service_decode(ptr: *const u8, len: size_t) -> *mut CustomService {
107  Box::into_raw(Box::new(
108  CustomService::decode(slice::from_raw_parts(ptr, len)).unwrap(),
109  ))
110 }
111 #[no_mangle]
112 pub unsafe extern "C" fn custom_service_encode(ptr: *const CustomService) -> *mut u8 {
113  let p = &*ptr;
114  let mut x = p.encode().unwrap();
115  let r = x.as_mut_ptr();
116  std::mem::forget(x);
117  r
118 }