Skip to content

Commit 97139c3

Browse files
committed
docs: add ffi docs
1 parent 412134b commit 97139c3

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

float-pigment-css/src/ffi.rs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,23 @@ impl<T> FfiResult<T> {
8181
}
8282

8383
/// # Safety
84-
///
84+
/// Create a new resource manager.
8585
#[export_name = "FPStyleSheetResourceNew"]
8686
pub unsafe extern "C" fn style_sheet_resource_new() -> FfiResult<RawMutPtr> {
8787
FfiResult::ok(Box::into_raw(Box::new(group::StyleSheetResource::new())) as RawMutPtr)
8888
}
89+
8990
/// # Safety
90-
///
91+
/// Free the resource manager.
9192
#[export_name = "FPStyleSheetResourceFree"]
9293
pub unsafe extern "C" fn style_sheet_resource_free(this: RawMutPtr) -> FfiResult<NullPtr> {
9394
check_null!((this), null());
9495
drop(Box::from_raw(this as *mut group::StyleSheetResource));
9596
FfiResult::ok(null())
9697
}
98+
9799
/// # Safety
98-
///
100+
/// Add a tag name prefix to the resource manager.
99101
#[export_name = "FPStyleSheetResourceAddTagNamePrefix"]
100102
pub unsafe extern "C" fn style_sheet_resource_add_tag_name_prefix(
101103
this: RawMutPtr,
@@ -109,8 +111,9 @@ pub unsafe extern "C" fn style_sheet_resource_add_tag_name_prefix(
109111
res.add_tag_name_prefix(&path, &prefix);
110112
FfiResult::ok(null())
111113
}
114+
112115
/// # Safety
113-
///
116+
/// Serialize the specified style sheet to the JSON format.
114117
#[cfg(all(feature = "serialize", feature = "serialize_json"))]
115118
#[export_name = "FPStyleSheetResourceSerializeJson"]
116119
pub unsafe extern "C" fn style_sheet_resource_serialize_json(
@@ -126,8 +129,9 @@ pub unsafe extern "C" fn style_sheet_resource_serialize_json(
126129
let ret = Box::into_raw(serial.into_boxed_str());
127130
FfiResult::ok(ret as *mut u8)
128131
}
132+
129133
/// # Safety
130-
///
134+
/// Serialize the specified style sheet to the binary format.
131135
#[cfg(feature = "serialize")]
132136
#[export_name = "FPStyleSheetResourceSerializeBincode"]
133137
pub unsafe extern "C" fn style_sheet_resource_serialize_bincode(
@@ -144,7 +148,7 @@ pub unsafe extern "C" fn style_sheet_resource_serialize_bincode(
144148
FfiResult::ok(ret as *mut u8)
145149
}
146150
/// # Safety
147-
///
151+
/// Add a style sheet to the resource manager.
148152
#[export_name = "FPStyleSheetResourceAddSource"]
149153
pub unsafe extern "C" fn style_sheet_resource_add_source(
150154
this: RawMutPtr,
@@ -162,8 +166,9 @@ pub unsafe extern "C" fn style_sheet_resource_add_source(
162166
}
163167
FfiResult::ok(null())
164168
}
169+
165170
/// # Safety
166-
///
171+
/// Add a style sheet to the resource manager with hooks.
167172
#[export_name = "FPStyleSheetResourceAddSourceWithHooks"]
168173
pub unsafe extern "C" fn style_sheet_resource_add_source_with_hooks(
169174
this: RawMutPtr,
@@ -184,7 +189,7 @@ pub unsafe extern "C" fn style_sheet_resource_add_source_with_hooks(
184189
}
185190

186191
/// # Safety
187-
///
192+
/// Add a style sheet to the resource manager from binary format.
188193
#[cfg(feature = "deserialize")]
189194
#[export_name = "FPStyleSheetResourceAddBincode"]
190195
pub unsafe extern "C" fn style_sheet_resource_add_bincode(
@@ -212,7 +217,7 @@ pub unsafe extern "C" fn style_sheet_resource_add_bincode(
212217
}
213218

214219
/// # Safety
215-
///
220+
/// Get the direct dependencies of the specified style sheet.
216221
#[export_name = "FPStyleSheetResourceDirectDependencies"]
217222
pub unsafe extern "C" fn style_sheet_resource_direct_dependencies(
218223
this: RawMutPtr,
@@ -227,7 +232,7 @@ pub unsafe extern "C" fn style_sheet_resource_direct_dependencies(
227232
}
228233

229234
/// # Safety
230-
///
235+
/// Generate the import index of the resource manager.
231236
#[export_name = "FPStyleSheetResourceGenerateImportIndex"]
232237
pub unsafe extern "C" fn style_sheet_resource_generate_import_index(
233238
this: RawMutPtr,
@@ -257,7 +262,7 @@ impl StyleSheetImportIndex {
257262
}
258263

259264
/// # Safety
260-
///
265+
/// Create a new style sheet import index.
261266
#[export_name = "FPStyleSheetImportIndexNew"]
262267
pub unsafe extern "C" fn style_sheet_import_index_new() -> FfiResult<RawMutPtr> {
263268
FfiResult::ok(
@@ -270,7 +275,7 @@ pub unsafe extern "C" fn style_sheet_import_index_new() -> FfiResult<RawMutPtr>
270275
}
271276

272277
/// # Safety
273-
///
278+
/// Free the style sheet import index.
274279
#[export_name = "FPStyleSheetImportIndexFree"]
275280
pub unsafe extern "C" fn style_sheet_import_index_free(this: RawMutPtr) -> FfiResult<NullPtr> {
276281
check_null!((this), null());
@@ -279,7 +284,7 @@ pub unsafe extern "C" fn style_sheet_import_index_free(this: RawMutPtr) -> FfiRe
279284
}
280285

281286
/// # Safety
282-
///
287+
/// Query and mark the dependencies of the specified style sheet.
283288
#[export_name = "FPStyleSheetImportIndexQueryAndMarkDependencies"]
284289
pub unsafe extern "C" fn style_sheet_import_index_query_and_mark_dependencies(
285290
this: RawMutPtr,
@@ -296,7 +301,7 @@ pub unsafe extern "C" fn style_sheet_import_index_query_and_mark_dependencies(
296301
}
297302

298303
/// # Safety
299-
///
304+
/// List the dependencies of the specified style sheet.
300305
#[export_name = "FPStyleSheetImportIndexListDependencies"]
301306
pub unsafe extern "C" fn style_sheet_import_index_list_dependencies(
302307
this: RawMutPtr,
@@ -313,7 +318,7 @@ pub unsafe extern "C" fn style_sheet_import_index_list_dependencies(
313318
}
314319

315320
/// # Safety
316-
///
321+
/// List the dependency of the specified style sheet.
317322
#[export_name = "FPStyleSheetImportIndexListDependency"]
318323
pub unsafe extern "C" fn style_sheet_import_index_list_dependency(
319324
this: RawMutPtr,
@@ -329,7 +334,7 @@ pub unsafe extern "C" fn style_sheet_import_index_list_dependency(
329334
FfiResult::ok(Box::into_raw(Box::new(deps.into())))
330335
}
331336
/// # Safety
332-
///
337+
/// Add a style sheet to the import index from binary format.
333338
#[cfg(feature = "deserialize")]
334339
#[export_name = "FPStyleSheetImportIndexAddBincode"]
335340
pub unsafe extern "C" fn style_sheet_import_index_add_bincode(
@@ -386,7 +391,7 @@ pub unsafe extern "C" fn style_sheet_import_index_add_bincode(
386391
}
387392

388393
/// # Safety
389-
///
394+
/// Remove a style sheet from the style sheet import index.
390395
#[export_name = "FPStyleSheetImportIndexRemoveBincode"]
391396
pub unsafe extern "C" fn style_sheet_import_index_remove_bincode(
392397
this: RawMutPtr,
@@ -400,7 +405,7 @@ pub unsafe extern "C" fn style_sheet_import_index_remove_bincode(
400405
FfiResult::ok(null())
401406
}
402407
/// # Safety
403-
///
408+
/// Get the style sheet from the style sheet import index.
404409
#[export_name = "FPStyleSheetImportIndexGetStyleSheet"]
405410
pub unsafe extern "C" fn style_sheet_import_index_get_style_sheet(
406411
this: RawMutPtr,
@@ -416,7 +421,7 @@ pub unsafe extern "C" fn style_sheet_import_index_get_style_sheet(
416421
}
417422
}
418423
/// # Safety
419-
///
424+
/// Serialize the style sheet import index to the JSON format.
420425
#[cfg(all(feature = "serialize", feature = "serialize_json"))]
421426
#[export_name = "FPStyleSheetImportIndexSerializeJson"]
422427
pub unsafe extern "C" fn style_sheet_import_index_serialize_json(
@@ -431,7 +436,7 @@ pub unsafe extern "C" fn style_sheet_import_index_serialize_json(
431436
FfiResult::ok(ret as *mut u8)
432437
}
433438
/// # Safety
434-
///
439+
/// Serialize the style sheet import index to the binary format.
435440
#[cfg(feature = "serialize")]
436441
#[export_name = "FPStyleSheetImportIndexSerializeBincode"]
437442
pub unsafe extern "C" fn style_sheet_import_index_serialize_bincode(
@@ -446,7 +451,7 @@ pub unsafe extern "C" fn style_sheet_import_index_serialize_bincode(
446451
FfiResult::ok(ret as *mut u8)
447452
}
448453
/// # Safety
449-
///
454+
/// Deserialize the style sheet import index from the JSON format.
450455
#[cfg(all(feature = "deserialize", feature = "deserialize_json"))]
451456
#[export_name = "FPStyleSheetImportIndexDeserializeJson"]
452457
pub unsafe extern "C" fn style_sheet_import_index_deserialize_json(
@@ -490,7 +495,7 @@ pub unsafe extern "C" fn style_sheet_import_index_deserialize_bincode(
490495
)
491496
}
492497
/// # Safety
493-
///
498+
/// Merge the style sheet import index from binary format.
494499
#[cfg(feature = "deserialize")]
495500
#[export_name = "FPStyleSheetImportIndexMergeBincode"]
496501
pub unsafe extern "C" fn style_sheet_import_index_merge_bincode(
@@ -514,7 +519,7 @@ pub unsafe extern "C" fn style_sheet_import_index_merge_bincode(
514519
}
515520

516521
/// # Safety
517-
///
522+
/// Free the buffer.
518523
#[export_name = "FPBufferFree"]
519524
pub unsafe extern "C" fn buffer_free(buffer_ptr: *mut u8, buffer_len: usize) -> FfiResult<NullPtr> {
520525
check_null!((buffer_ptr), null());
@@ -524,7 +529,7 @@ pub unsafe extern "C" fn buffer_free(buffer_ptr: *mut u8, buffer_len: usize) ->
524529
}
525530

526531
/// # Safety
527-
///
532+
/// Free the array of string references.
528533
#[export_name = "FPArrayStrRefFree"]
529534
pub unsafe extern "C" fn array_str_ref_free(x: *mut Array<StrRef>) -> FfiResult<NullPtr> {
530535
check_null!((x), null());
@@ -533,7 +538,7 @@ pub unsafe extern "C" fn array_str_ref_free(x: *mut Array<StrRef>) -> FfiResult<
533538
}
534539

535540
/// # Safety
536-
///
541+
/// Free the array of warnings.
537542
#[export_name = "FPArrayWarningFree"]
538543
pub unsafe extern "C" fn array_warning_free(
539544
warnings: *mut Array<parser::Warning>,
@@ -544,7 +549,7 @@ pub unsafe extern "C" fn array_warning_free(
544549
}
545550

546551
/// # Safety
547-
///
552+
/// Parse the inline style from the string.
548553
#[export_name = "FPParseInlineStyle"]
549554
pub unsafe extern "C" fn parse_inline_style(
550555
inline_style_text_ptr: *const c_char,
@@ -580,16 +585,18 @@ pub unsafe extern "C" fn parse_inline_style(
580585
let inline_rule = InlineRule::new(properties, important);
581586
FfiResult::ok(Box::into_raw(Box::new(inline_rule)))
582587
}
588+
583589
/// # Safety
584-
///
590+
/// Free the inline style.
585591
#[export_name = "FPInlineStyleFree"]
586592
pub unsafe extern "C" fn inline_style_free(inline_rule: *mut InlineRule) -> FfiResult<NullPtr> {
587593
check_null!((inline_rule), null());
588594
drop(Box::from_raw(inline_rule));
589595
FfiResult::ok(null())
590596
}
597+
591598
/// # Safety
592-
///
599+
/// Parse the style sheet from the string.
593600
#[export_name = "FPParseStyleSheetFromString"]
594601
pub unsafe extern "C" fn parse_style_sheet_from_string(
595602
style_text_ptr: *const c_char,
@@ -600,8 +607,9 @@ pub unsafe extern "C" fn parse_style_sheet_from_string(
600607
let style_sheet = StyleSheet::from_sheet(&compiled_style_sheet);
601608
FfiResult::ok(Box::into_raw(Box::new(style_sheet)))
602609
}
610+
603611
/// # Safety
604-
///
612+
/// Parse the selector from the string.
605613
#[export_name = "FPParseSelectorFromString"]
606614
pub unsafe extern "C" fn parse_selector_from_string(
607615
selector_text_ptr: *const c_char,
@@ -611,8 +619,9 @@ pub unsafe extern "C" fn parse_selector_from_string(
611619
let selector = Selector::from_string(&selector_text);
612620
FfiResult::ok(Box::into_raw(Box::new(selector)))
613621
}
622+
614623
/// # Safety
615-
///
624+
/// Free the selector.
616625
#[export_name = "FPSelectorFree"]
617626
pub unsafe extern "C" fn selector_free(selector: *mut Selector) -> FfiResult<NullPtr> {
618627
check_null!((selector), null());
@@ -621,7 +630,7 @@ pub unsafe extern "C" fn selector_free(selector: *mut Selector) -> FfiResult<Nul
621630
}
622631

623632
/// # Safety
624-
///
633+
/// Free the style sheet.
625634
#[export_name = "FPStyleSheetFree"]
626635
pub unsafe extern "C" fn style_sheet_free(style_sheet: *mut StyleSheet) -> FfiResult<NullPtr> {
627636
check_null!((style_sheet), null());
@@ -630,7 +639,7 @@ pub unsafe extern "C" fn style_sheet_free(style_sheet: *mut StyleSheet) -> FfiRe
630639
}
631640

632641
/// # Safety
633-
///
642+
/// Get the version of the style sheet in the binary format.
634643
#[cfg(feature = "deserialize")]
635644
#[export_name = "FPStyleSheetBincodeVersion"]
636645
pub unsafe extern "C" fn style_sheet_bincode_version(
@@ -672,7 +681,7 @@ pub unsafe extern "C" fn style_sheet_bincode_version(
672681
}
673682

674683
/// # Safety
675-
///
684+
/// Get the version of the CSS parser.
676685
#[export_name = "FPCssParserVersion"]
677686
pub unsafe extern "C" fn css_parser_version() -> FfiResult<*mut StrRef> {
678687
let version = env!("CARGO_PKG_VERSION").to_string().into();
@@ -689,7 +698,7 @@ pub struct ColorValue {
689698
}
690699

691700
/// # Safety
692-
///
701+
/// Parse the color from the string.
693702
#[export_name = "FPParseColorFromString"]
694703
pub unsafe extern "C" fn parse_color_from_string(source: *const c_char) -> FfiResult<ColorValue> {
695704
check_null!((source), ColorValue::default());
@@ -704,7 +713,7 @@ pub unsafe extern "C" fn parse_color_from_string(source: *const c_char) -> FfiRe
704713
}
705714

706715
/// # Safety
707-
///
716+
/// Substitute the variable in the expression.
708717
#[export_name = "FPSubstituteVariable"]
709718
pub unsafe extern "C" fn substitute_variable(
710719
expr_ptr: *const c_char,
@@ -724,7 +733,7 @@ pub unsafe extern "C" fn substitute_variable(
724733
}
725734

726735
/// # Safety
727-
///
736+
/// Free the string.
728737
#[export_name = "FPStrFree"]
729738
pub unsafe extern "C" fn str_free(ptr: *const c_char) -> FfiResult<NullPtr> {
730739
check_null!((ptr), null());

0 commit comments

Comments
 (0)