restructure api
This commit is contained in:
parent
efaa52faa1
commit
8320ee2d80
32 changed files with 561 additions and 544 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::cp437_grid::Cp437Grid;
|
||||
use servicepoint::{Grid, primitive_grid::SeriesError};
|
||||
use servicepoint::{Grid, SetValueSeriesError};
|
||||
use std::convert::Into;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
|
@ -107,7 +107,10 @@ impl CharGrid {
|
|||
.unwrap()
|
||||
.get_row(y as usize)
|
||||
.map(String::from_iter)
|
||||
.ok_or(CharGridError::OutOfBounds {index: y, size: self.height()})
|
||||
.ok_or(CharGridError::OutOfBounds {
|
||||
index: y,
|
||||
size: self.height(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_col(&self, x: u64) -> Result<String, CharGridError> {
|
||||
|
@ -116,11 +119,16 @@ impl CharGrid {
|
|||
.unwrap()
|
||||
.get_col(x as usize)
|
||||
.map(String::from_iter)
|
||||
.ok_or(CharGridError::OutOfBounds {index: x, size: self.width()})
|
||||
.ok_or(CharGridError::OutOfBounds {
|
||||
index: x,
|
||||
size: self.width(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_cp437(&self) -> Arc<Cp437Grid> {
|
||||
Cp437Grid::internal_new(servicepoint::Cp437Grid::from(&*self.actual.read().unwrap()))
|
||||
Cp437Grid::internal_new(servicepoint::Cp437Grid::from(
|
||||
&*self.actual.read().unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,9 +141,7 @@ impl CharGrid {
|
|||
|
||||
fn str_to_char(value: String) -> Result<char, CharGridError> {
|
||||
if value.len() != 1 {
|
||||
return Err(CharGridError::StringNotOneChar {
|
||||
value,
|
||||
});
|
||||
return Err(CharGridError::StringNotOneChar { value });
|
||||
}
|
||||
|
||||
let value = value.chars().nth(0).unwrap();
|
||||
|
@ -143,16 +149,16 @@ impl CharGrid {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<SeriesError> for CharGridError {
|
||||
fn from(e: SeriesError) -> Self {
|
||||
impl From<SetValueSeriesError> for CharGridError {
|
||||
fn from(e: SetValueSeriesError) -> Self {
|
||||
match e {
|
||||
SeriesError::OutOfBounds { index, size } => {
|
||||
SetValueSeriesError::OutOfBounds { index, size } => {
|
||||
CharGridError::OutOfBounds {
|
||||
index: index as u64,
|
||||
size: size as u64,
|
||||
}
|
||||
}
|
||||
SeriesError::InvalidLength { actual, expected } => {
|
||||
SetValueSeriesError::InvalidLength { actual, expected } => {
|
||||
CharGridError::InvalidSeriesLength {
|
||||
actual: actual as u64,
|
||||
expected: expected as u64,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, uniffi::Record)]
|
||||
#[derive(
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, uniffi::Record,
|
||||
)]
|
||||
pub struct Constants {
|
||||
pub tile_size: u64,
|
||||
pub tile_width: u64,
|
||||
|
@ -10,7 +12,7 @@ pub struct Constants {
|
|||
|
||||
#[uniffi::export]
|
||||
fn get_constants() -> Constants {
|
||||
Constants {
|
||||
Constants {
|
||||
tile_size: servicepoint::TILE_SIZE as u64,
|
||||
tile_width: servicepoint::TILE_WIDTH as u64,
|
||||
tile_height: servicepoint::TILE_HEIGHT as u64,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::char_grid::CharGrid;
|
||||
use servicepoint::{DataRef, Grid};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use crate::char_grid::CharGrid;
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Cp437Grid {
|
||||
|
@ -72,6 +72,8 @@ impl Cp437Grid {
|
|||
}
|
||||
|
||||
pub fn to_utf8(&self) -> Arc<CharGrid> {
|
||||
CharGrid::internal_new(servicepoint::CharGrid::from(&*self.actual.read().unwrap()))
|
||||
CharGrid::internal_new(servicepoint::CharGrid::from(
|
||||
&*self.actual.read().unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ mod char_grid;
|
|||
mod command;
|
||||
mod compression_code;
|
||||
mod connection;
|
||||
mod constants;
|
||||
mod cp437_grid;
|
||||
mod errors;
|
||||
mod constants;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue