Skip to content

Commit 907346f

Browse files
committed
feat: better ffi error impl
1 parent 97139c3 commit 907346f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

float-pigment-css/src/ffi.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::parser::property_value::var::{
2424
};
2525
use crate::sheet;
2626
use group::drop_css_extension;
27+
use group::StyleSheetImportIndex as StyleSheetImportIndexImpl;
2728
use parser::Warning;
2829
use sheet::borrow::{Array, StyleSheet};
2930
use sheet::str_store::StrRef;
@@ -68,14 +69,14 @@ pub struct FfiResult<T> {
6869
impl<T> FfiResult<T> {
6970
pub fn ok(value: T) -> Self {
7071
Self {
71-
err: FfiErrorCode::None,
7272
value,
73+
err: FfiErrorCode::None,
7374
}
7475
}
7576
pub fn error(err: FfiErrorCode, default: T) -> Self {
7677
Self {
77-
err,
7878
value: default,
79+
err,
7980
}
8081
}
8182
}
@@ -251,7 +252,7 @@ pub unsafe extern "C" fn style_sheet_resource_generate_import_index(
251252
type StyleSheetMap = HashMap<String, StyleSheet>;
252253

253254
struct StyleSheetImportIndex {
254-
inner: group::StyleSheetImportIndex,
255+
inner: StyleSheetImportIndexImpl,
255256
map: StyleSheetMap,
256257
}
257258

@@ -267,7 +268,7 @@ impl StyleSheetImportIndex {
267268
pub unsafe extern "C" fn style_sheet_import_index_new() -> FfiResult<RawMutPtr> {
268269
FfiResult::ok(
269270
StyleSheetImportIndex {
270-
inner: group::StyleSheetImportIndex::new(),
271+
inner: StyleSheetImportIndexImpl::new(),
271272
map: StyleSheetMap::default(),
272273
}
273274
.into_raw(),
@@ -461,7 +462,7 @@ pub unsafe extern "C" fn style_sheet_import_index_deserialize_json(
461462
let json = CStr::from_ptr(json).to_string_lossy();
462463
FfiResult::ok(
463464
StyleSheetImportIndex {
464-
inner: group::StyleSheetImportIndex::deserialize_json(&json),
465+
inner: StyleSheetImportIndexImpl::deserialize_json(&json),
465466
map: StyleSheetMap::default(),
466467
}
467468
.into_raw(),
@@ -481,14 +482,11 @@ pub unsafe extern "C" fn style_sheet_import_index_deserialize_bincode(
481482
let bincode: *mut [u8] = core::slice::from_raw_parts_mut(buffer_ptr, buffer_len);
482483
FfiResult::ok(
483484
StyleSheetImportIndex {
484-
inner: group::StyleSheetImportIndex::deserialize_bincode_zero_copy(
485-
bincode,
486-
move || {
487-
if let Some(drop_fn) = drop_fn {
488-
drop_fn(drop_args);
489-
}
490-
},
491-
),
485+
inner: StyleSheetImportIndexImpl::deserialize_bincode_zero_copy(bincode, move || {
486+
if let Some(drop_fn) = drop_fn {
487+
drop_fn(drop_args);
488+
}
489+
}),
492490
map: StyleSheetMap::default(),
493491
}
494492
.into_raw(),

0 commit comments

Comments
 (0)