basics for uniffi
This commit is contained in:
parent
12ba47a281
commit
07a1b8810c
19 changed files with 1353 additions and 3 deletions
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
uniffi_bindgen_cs::main().unwrap();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
uniffi::uniffi_bindgen_main()
|
||||
}
|
20
crates/servicepoint_binding_uniffi/src/command.rs
Normal file
20
crates/servicepoint_binding_uniffi/src/command.rs
Normal 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 })
|
||||
}
|
||||
}
|
23
crates/servicepoint_binding_uniffi/src/connection.rs
Normal file
23
crates/servicepoint_binding_uniffi/src/connection.rs
Normal 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()})
|
||||
}
|
||||
}
|
4
crates/servicepoint_binding_uniffi/src/lib.rs
Normal file
4
crates/servicepoint_binding_uniffi/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
uniffi::setup_scaffolding!();
|
||||
|
||||
mod command;
|
||||
mod connection;
|
Loading…
Add table
Add a link
Reference in a new issue