basics for uniffi

This commit is contained in:
Vinzenz Schroeter 2024-11-02 23:15:54 +01:00
parent 12ba47a281
commit 07a1b8810c
19 changed files with 1353 additions and 3 deletions

View file

@ -0,0 +1,3 @@
fn main() {
uniffi_bindgen_cs::main().unwrap();
}

View file

@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}

View file

@ -0,0 +1,20 @@
use std::sync::Arc;
#[uniffi::export]
trait Command: Send + Sync {}
#[derive(uniffi::Object)]
pub struct Clear {
actual: servicepoint::Command,
}
#[uniffi::export]
impl Command for Clear {}
#[uniffi::export]
impl Clear {
#[uniffi::constructor]
pub fn new() -> Arc<Self> {
let actual = servicepoint::Command::Clear;
Arc::new(Clear { actual })
}
}

View file

@ -0,0 +1,23 @@
use std::{sync::Arc};
#[derive(uniffi::Object)]
pub struct Connection {
actual: servicepoint::Connection,
}
#[derive(uniffi::Error, thiserror::Error, Debug)]
pub enum ConnectionError {
#[error("An IO error occured: {error}")]
IOError {
error: String}
}
#[uniffi::export]
impl Connection {
#[uniffi::constructor]
pub fn new(host: String) -> Result<Arc<Self>, ConnectionError> {
servicepoint::Connection::open(host)
.map(|actual|Arc::new(Connection { actual}) )
.map_err(|err| ConnectionError::IOError { error: err.to_string()})
}
}

View file

@ -0,0 +1,4 @@
uniffi::setup_scaffolding!();
mod command;
mod connection;