Intentionally unimplemented C API items (25 items) #56
developer0hye
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Overview
As of PR #55, 245 out of 270 libjpeg-turbo API items are implemented (91%). The remaining 25 items are intentionally left unimplemented because they are C-specific internal APIs that Rust's language features already handle better.
This discussion documents why each is unnecessary.
Memory Management (6 items)
These exist because C has no automatic memory management. Rust's ownership system (
Vec,Box,Drop) makes them redundant.jpeg_memory_mgr(pool allocator)alloc_small/alloc_large/alloc_sarray/alloc_barrayVec::with_capacity()/Box::new()request_virt_sarray/request_virt_barray/realize_virt_arrays/access_virt_sarray/access_virt_barrayVec<Vec<T>>free_pool/self_destructDroptrait auto-cleans upmax_memory_to_use/max_alloc_chunkDecoder::set_max_memory()tj3Alloc()/tj3Free()C Error Message System (9 items)
libjpeg uses a C-style error manager with function pointers, format strings, and message tables. Rust has
Result<T, E>,Displaytrait, andDecodeWarning— a strictly better approach.output_message()callbackJpegErrorimplementsDisplayformat_message()callbackJpegErrorimplementsDisplayreset_error_mgr()Encoder/Decoder(zero cost)trace_levelcontrolErrorHandler::trace()callback already implementednum_warningscounterImage.warnings/DecodeWarninglistmsg_code/msg_parmJpegErrorenum variants carry structured datajpeg_message_table/addon_message_tableDisplayimpltj3GetErrorStr()/tj3GetErrorCode()JpegErrorimplementsDisplay+ pattern matchingjpeg_resync_to_restart()C State Machine Reset Functions (4 items)
In C, you reuse a
jpeg_compress_structacross multiple images and reset it. In Rust, you just create a newEncoder::new()— it's zero-cost and avoids stale state bugs.jpeg_default_qtables()Encoder— defaults are resetjpeg_default_colorspace()Encoderhas default colorspacejpeg_alloc_huff_table().huffman_dc_table()/.huffman_ac_table()builder methodsjpeg_suppress_tables()Truly Niche / Obsolete (4 items)
CCIR601_samplinginput_gammain_color_space/jpeg_color_spaceindependent control.colorspace()builder already provides explicit overrideq_scale_factor[NUM_QUANT_TBLS].quality_factor()(PR #31)Could Implement But Very Low Value (2 items)
jpeg_write_icc_profile()Encoder.icc_profile()during compressionjpeg_write_tables()Summary
All 25 items fall into categories where Rust's language design provides a better alternative. Implementing them would add API surface without adding value, and could confuse users into using C patterns instead of idiomatic Rust.
If any of these become needed for FFI/C interop in the future, they can be added behind a
ffifeature flag.All reactions