hakuban 0.7.2

Data-object sharing library
Documentation
#![allow(clippy::not_unsafe_ptr_arg_deref)]

use futures::{stream::StreamExt, FutureExt};

use super::{ffi_future::FFIFuture, FFIObjectDescriptor, FFIResult};
use crate::{object::state_sink::ObjectStateSink, LocalExchange, ObjectExposeContract};



#[no_mangle]
pub extern "C" fn hakuban_object_expose_contract_new(local_exchange: *mut LocalExchange, descriptor: *mut FFIObjectDescriptor) -> *mut ObjectExposeContract {
	let local_exchange = unsafe { local_exchange.as_mut().unwrap() };
	let descriptor = unsafe { descriptor.as_mut().unwrap() };
	Box::into_raw(Box::new(local_exchange.object(descriptor.descriptor.clone()).expose()))
}


#[no_mangle]
pub extern "C" fn hakuban_object_expose_contract_drop(object_expose_pointer: *mut ObjectExposeContract) {
	drop(unsafe { Box::from_raw(object_expose_pointer) });
}


#[no_mangle]
pub extern "C" fn hakuban_object_expose_contract_terminate(object_expose_pointer: *mut ObjectExposeContract) {
	let object_expose: &mut ObjectExposeContract = unsafe { object_expose_pointer.as_mut().unwrap() };
	object_expose.terminate();
}


#[no_mangle]
pub extern "C" fn hakuban_object_expose_contract_next(object_expose_pointer: *mut ObjectExposeContract) -> *mut FFIFuture<*mut ObjectStateSink> {
	let object_expose: &mut ObjectExposeContract = unsafe { object_expose_pointer.as_mut().unwrap() };
	Box::into_raw(Box::new(FFIFuture::new(object_expose.next().map(|item| item.map(|object_state_sink| Box::into_raw(Box::new(object_state_sink))).into()))))
}


#[no_mangle]
pub extern "C" fn hakuban_object_expose_contract_ready(object_expose_pointer: *mut ObjectExposeContract) -> FFIResult<*mut ObjectStateSink> {
	let object_expose: &mut ObjectExposeContract = unsafe { object_expose_pointer.as_mut().unwrap() };
	if let Some(object_state_sink) = object_expose.ready() {
		FFIResult::ok(Box::into_raw(Box::new(object_state_sink)))
	} else {
		FFIResult::error(super::FFIResultStatus::NotAvailable)
	}
}