1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! # Truston
//!
//! A high-performance Rust client library for [NVIDIA Triton Inference Server](https://github.com/triton-inference-server/server).
//!
//! Truston provides a type-safe, ergonomic interface for communicating with Triton Inference Server
//! via its REST API. It supports multiple data types, seamless NDArray integration, and async operations.
//!
//! ## Features
//!
//! - **Type-safe inference**: Strongly-typed input/output handling with compile-time guarantees
//! - **Multiple data types**: Support for all Triton data types (INT8, INT16, INT32, INT64, UINT8, UINT16, UINT64, FP32, FP64, BOOL, STRING, BF16)
//! - **NDArray integration**: Direct conversion between `ndarray::ArrayD` and Triton tensors
//! - **Async/await**: Built on `tokio` for efficient concurrent operations
//! - **Error handling**: Comprehensive error types with context
//!
//! ## Quick Start
//!
//! ```no_run
//! use truston::client::triton_client::TritonRestClient;
//! use truston::client::io::InferInput;
//! use ndarray::ArrayD;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a client
//! let client = TritonRestClient::new("http://localhost:50000");
//!
//! // Check if server is alive
//! let is_alive = client.is_server_live().await?;
//! println!("Server is alive: {}", is_alive);
//!
//! // Prepare input data
//! let input_data: ArrayD<f32> = ArrayD::zeros(ndarray::IxDyn(&[1, 224, 224, 3]));
//! let input = InferInput::from_ndarray("input", input_data);
//!
//! // Run inference
//! let results = client.infer(vec![input], "my_model").await?;
//!
//! // Access results
//! for output in results.outputs {
//! println!("Output: {} with shape {:?}", output.name, output.shape);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Creating Inputs
//!
//! ### From NDArray
//!
//! ```
//! use truston::client::io::InferInput;
//! use ndarray::array;
//!
//! let arr = array![[1.0, 2.0], [3.0, 4.0]].into_dyn();
//! let input = InferInput::from_ndarray("my_input", arr);
//! ```
//!
//! ### From Raw Vectors
//!
//! ```
//! use truston::client::io::{InferInput, DataType};
//!
//! let data = DataType::F32(vec![1.0, 2.0, 3.0, 4.0]);
//! let input = InferInput::new(
//! "my_input".to_string(),
//! vec![2, 2], // shape
//! data
//! );
//! ```
//!
//! ## Handling Outputs
//!
//! ```no_run
//! # use truston::client::triton_client::TritonRestClient;
//! # use truston::client::io::InferInput;
//! # use ndarray::ArrayD;
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # let client = TritonRestClient::new("http://localhost:8000");
//! # let input_data: ArrayD<f32> = ArrayD::zeros(ndarray::IxDyn(&[1, 3]));
//! # let input = InferInput::from_ndarray("input", input_data);
//! let results = client.infer(vec![input], "my_model").await?;
//!
//! for output in results.outputs {
//! // Convert to vector
//! if let Some(vec) = output.data.as_f32_vec() {
//! println!("F32 output: {:?}", vec);
//! }
//!
//! // Convert to ndarray
//! if let Some(arr) = output.data.to_ndarray_f32(&output.shape) {
//! println!("Array shape: {:?}", arr.shape());
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Supported Data Types
//!
//! | Rust Type | Triton Type | DataType Variant |
//! |-----------|-------------|------------------|
//! | `bool` | BOOL | `DataType::Bool` |
//! | `u8` | UINT8 | `DataType::U8` |
//! | `u16` | UINT16 | `DataType::U16` |
//! | `u64` | UINT64 | `DataType::U64` |
//! | `i8` | INT8 | `DataType::I8` |
//! | `i16` | INT16 | `DataType::I16` |
//! | `i32` | INT32 | `DataType::I32` |
//! | `i64` | INT64 | `DataType::I64` |
//! | `f32` | FP32 | `DataType::F32` |
//! | `f64` | FP64 | `DataType::F64` |
//! | `String` | STRING | `DataType::String` |
//! | `u16` (raw) | BF16 | `DataType::Bf16` |
//!
//! ## Error Handling
//!
//! All operations return `Result<T, TrustonError>` for proper error handling:
//!
//! ```no_run
//! # use truston::client::triton_client::TritonRestClient;
//! # use truston::utils::errors::TrustonError;
//! # #[tokio::main]
//! # async fn main() {
//! let client = TritonRestClient::new("http://localhost:50000");
//!
//! match client.is_server_live().await {
//! Ok(true) => println!("Server is ready"),
//! Ok(false) => println!("Server is not ready"),
//! Err(TrustonError::Http(msg)) => eprintln!("Connection error: {}", msg),
//! Err(TrustonError::ServerError{status: code, message: msg}) => {
//! eprintln!("Server error {}: {}", code, msg)
//! }
//! Err(e) => eprintln!("Error: {:?}", e),
//! }
//! # }
//! ```
//!
//! ## Requirements
//! - Triton Inference Server (any version supporting v2 REST API)
//!
//! ## License
//!
//! Licensed under either of Apache License, Version 2.0 or MIT license at your option.
// Re-export commonly used items for convenience
pub use ;
pub use ;
pub use TrustonError;
/// Initialize tracing subscriber for logging.
///
/// This sets up a formatted tracing subscriber with INFO level logging.
/// Call this once at the start of your application to enable logging.
///
/// # Example
///
/// ```
/// truston::init_tracing();
/// // Now tracing macros will output logs
/// ```