split servicepoint_binding_uniffi into own crate
Some checks failed
Rust / build (push) Has been cancelled
Some checks failed
Rust / build (push) Has been cancelled
This commit is contained in:
parent
2f7a2dfd62
commit
21931f847f
94 changed files with 158 additions and 9856 deletions
36
src/connection.rs
Normal file
36
src/connection.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::errors::ServicePointError;
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Connection {
|
||||
actual: servicepoint::Connection,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl Connection {
|
||||
#[uniffi::constructor]
|
||||
pub fn new(host: String) -> Result<Arc<Self>, ServicePointError> {
|
||||
servicepoint::Connection::open(host)
|
||||
.map(|actual| Arc::new(Connection { actual }))
|
||||
.map_err(|err| ServicePointError::IoError {
|
||||
error: err.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn new_fake() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
actual: servicepoint::Connection::Fake,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
|
||||
self.actual.send(command.actual.clone()).map_err(|err| {
|
||||
ServicePointError::IoError {
|
||||
error: format!("{err:?}"),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue