Skip to content

little added abstraction, c++ ffi shell#6

Closed
kishangoli wants to merge 2 commits into
mainfrom
kishan
Closed

little added abstraction, c++ ffi shell#6
kishangoli wants to merge 2 commits into
mainfrom
kishan

Conversation

@kishangoli

Copy link
Copy Markdown
Collaborator

added some small api abstraction, dynamically allocating space for when we shift implementation. added ffi shell for rust -> c++ comms

Copilot AI review requested due to automatic review settings May 15, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a small abstraction layer around the vector engine to allow swapping implementations later, and adds a minimal C++ FFI “shell” compiled via build.rs to support future Rust ↔ C++ communication.

Changes:

  • Generalize the in-memory engine storage to a boxed dyn VectorEngine in application state.
  • Move dimension() onto the VectorEngine trait so API handlers can validate vector sizes through the abstraction.
  • Add a C++ FFI stub (native/...) and a Rust build script using cc to compile it.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/state.rs Store the engine behind Box<dyn VectorEngine> for implementation swapping.
src/engine.rs Promote dimension() to the VectorEngine trait and implement it for FlatIndex.
src/api/handlers.rs Remove now-unneeded VectorEngine import; handlers call dimension() through the state-held trait object.
native/src/vector_engine_ffi.cpp Add initial C++ FFI allocation/free stubs.
native/include/vector_engine_ffi.h Add FFI header declaring the C ABI surface.
Cargo.toml Add cc as a build-dependency.
Cargo.lock Lockfile updates for cc and transitive deps.
build.rs Compile the C++ FFI stub during the Rust build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/state.rs
Comment on lines 1 to 8
use std::sync::{Arc, Mutex};

use crate::engine::FlatIndex;
use crate::engine::{FlatIndex, VectorEngine};

#[derive(Clone)]
pub struct AppState {
pub engine: Arc<Mutex<FlatIndex>>,
pub engine: Arc<Mutex<Box<dyn VectorEngine + Send>>>,
}
Comment on lines +5 to +11

extern "C" {

NativeVectorEngine* native_vector_engine_new();
void native_vector_engine_free(NativeVectorEngine* engine);

}
Comment thread build.rs
Comment on lines +1 to +7
fn main() {
cc::Build::new()
.cpp(true)
.file("native/src/vector_engine_ffi.cpp")
.include("native/include")
.std("c++17")
.compile("vector_engine_ffi");
@kishangoli kishangoli closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants