diff --git a/internal/core/thirdparty/tantivy/tantivy-binding/include/tantivy-binding.h b/internal/core/thirdparty/tantivy/tantivy-binding/include/tantivy-binding.h index 7e5c1a96c0bd3..09b80a85d7ab6 100644 --- a/internal/core/thirdparty/tantivy/tantivy-binding/include/tantivy-binding.h +++ b/internal/core/thirdparty/tantivy/tantivy-binding/include/tantivy-binding.h @@ -67,6 +67,10 @@ void free_rust_result(RustResult result); void free_rust_error(const char *error); +RustResult test_enum_with_array(); + +RustResult test_enum_with_ptr(); + void print_vector_of_strings(const char *const *ptr, uintptr_t len); void *create_hashmap(); diff --git a/internal/core/thirdparty/tantivy/tantivy-binding/src/array.rs b/internal/core/thirdparty/tantivy/tantivy-binding/src/array.rs index e03a90295b853..521269ddce29f 100644 --- a/internal/core/thirdparty/tantivy/tantivy-binding/src/array.rs +++ b/internal/core/thirdparty/tantivy/tantivy-binding/src/array.rs @@ -159,3 +159,17 @@ macro_rules! cstr_to_str { } }; } + + +#[no_mangle] +pub extern "C" fn test_enum_with_array() -> RustResult { + let array = vec![1, 2, 3]; + RustResult::from(Result::Ok(array)) +} + +#[no_mangle] +pub extern "C" fn test_enum_with_ptr() -> RustResult { + let ptr = Box::into_raw(Box::new(1)); + RustResult::from(Result::Ok(ptr as *mut c_void)) +} + diff --git a/internal/core/unittest/CMakeLists.txt b/internal/core/unittest/CMakeLists.txt index 56123c7ef06e6..0568489da79c6 100644 --- a/internal/core/unittest/CMakeLists.txt +++ b/internal/core/unittest/CMakeLists.txt @@ -87,6 +87,7 @@ set(MILVUS_TEST_FILES test_utils.cpp test_chunked_segment.cpp test_chunked_column.cpp + test_rust_result.cpp ) if ( INDEX_ENGINE STREQUAL "cardinal" ) diff --git a/internal/core/unittest/test_rust_result.cpp b/internal/core/unittest/test_rust_result.cpp new file mode 100644 index 0000000000000..cbbf895d834b3 --- /dev/null +++ b/internal/core/unittest/test_rust_result.cpp @@ -0,0 +1,14 @@ + +#include +#include "gtest/gtest.h" +#include "tantivy-binding.h" +TEST(RustResultTest, TestResult) { + auto arr = test_enum_with_array(); + auto len = arr.value.rust_array._0.len; + for (size_t i = 0; i < len; i++) { + EXPECT_EQ(i + 1, arr.value.rust_array._0.array[i]); + } + + auto ptr = test_enum_with_ptr(); + EXPECT_EQ(1, *static_cast(ptr.value.ptr._0)); +} \ No newline at end of file