compact-enc-det-sys

Crates.iocompact-enc-det-sys
lib.rscompact-enc-det-sys
version0.1.0
created_at2025-12-12 14:17:52.900352+00
updated_at2025-12-12 14:17:52.900352+00
descriptionLow-level FFI bindings to the Compact Encoding Detection (CED) C++ library
homepagehttps://github.com/greenhat616/compact_enc_det_rs
repositoryhttps://github.com/greenhat616/compact_enc_det_rs
max_upload_size
id1981605
size1,504,627
Jonson Petard (greenhat616)

documentation

https://docs.rs/compact-enc-det

README

compact-enc-det-sys

Crates.io Documentation License: MIT

Low-level FFI bindings to the Compact Encoding Detection (CED) C++ library.

Overview

This crate provides unsafe FFI bindings to Google's Compact Encoding Detection library using cxx. For most use cases, you should use the high-level compact-enc-det crate instead, which provides a safe and ergonomic Rust API.

When to Use This Crate

Use compact-enc-det-sys directly only if you need:

  • Direct access to the C++ API
  • Custom build configurations
  • To build your own higher-level wrapper

For normal encoding detection tasks, use the compact-enc-det crate.

Building

This crate uses cxx and cxx-build to generate bindings and compile the C++ library. The C++ source code is included as a git submodule.

Prerequisites

  • Rust 1.70+
  • A C++ compiler (GCC, Clang, or MSVC)
  • CMake (optional, for standalone C++ builds)

Build Process

The build happens automatically via build.rs:

  1. The C++ library is compiled from source in libs/compact_enc_det
  2. CXX generates the Rust-C++ bridge code
  3. Everything is linked together

Usage

use compact_enc_det_sys::ced_detect_encoding;

let text = b"Hello, world!";
let result = ced_detect_encoding(
    text,
    "",    // url_hint
    "",    // http_charset_hint
    "",    // meta_charset_hint
    -1,    // encoding_hint
    -1,    // language_hint
    2,     // corpus_type (QUERY_CORPUS)
    true,  // ignore_7bit_mail_encodings
);

println!("Encoding: {}", result.encoding);
println!("MIME name: {}", result.mime_name);
println!("Is reliable: {}", result.is_reliable);

API

ced_detect_encoding

pub fn ced_detect_encoding(
    bytes: &[u8],
    url_hint: &str,
    http_charset_hint: &str,
    meta_charset_hint: &str,
    encoding_hint: i32,
    language_hint: i32,
    corpus_type: i32,
    ignore_7bit_mail_encodings: bool,
) -> CedResult

CedResult

pub struct CedResult {
    pub mime_name: String,
    pub encoding: i32,
    pub bytes_consumed: i32,
    pub is_reliable: bool,
}

License

MIT License - see LICENSE file for details.

The underlying C++ library (google/compact_enc_det) is licensed under the Apache License 2.0.

See Also

  • compact-enc-det - Compact Encoding Detection (CED) C++ library
  • CXX - Safe interop between Rust and C++
Commit count: 0

cargo fmt