mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-19 02:20:12 +01:00
24 lines
599 B
Rust
24 lines
599 B
Rust
|
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()})
|
||
|
}
|
||
|
}
|