From 5f7c0b67c33ab63b7660d7fe19cacabdfeccfafb Mon Sep 17 00:00:00 2001 From: Morgan Funtowicz Date: Fri, 2 Aug 2024 22:18:18 +0000 Subject: [PATCH] (ffi) add template specialization to catch and convert to Rust Result --- backends/trtllm/include/ffi.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backends/trtllm/include/ffi.h b/backends/trtllm/include/ffi.h index a3544981..55f90f9f 100644 --- a/backends/trtllm/include/ffi.h +++ b/backends/trtllm/include/ffi.h @@ -14,6 +14,18 @@ namespace huggingface::tgi::backends { class TensorRtLlmBackendImpl; } +// Template to support returning error from TllmException back to Rust in a Result<> +#include + +namespace rust::behavior { + template + static void trycatch(Try &&func, Fail &&fail) noexcept try { + func(); + } catch (tensorrt_llm::common::TllmException &e) { + fail(e.what()); + } +} + #include "backends/trtllm/src/lib.rs.h" namespace huggingface::tgi::backends {