pub struct Json<T>(pub T);Expand description
Wrapper for returning serializable values as JSON tool output.
Implements From<Json<T>> for ToolOutput so it works with the
#[llm_tool] macro’s .into() conversion — no Result wrapper needed
for infallible serialization.
§Panics
The From conversion panics if serde_json::to_string fails.
This only happens with broken Serialize implementations (e.g.,
maps with non-string keys). For explicit error handling, use
ToolOutput::json() instead.
§Example
use llm_tool::{Json, ToolOutput};
use serde::Serialize;
#[derive(Serialize)]
struct Weather {
temp: f64,
city: String,
}
let output: ToolOutput = Json(Weather {
temp: 72.0,
city: "NYC".into(),
})
.into();
assert!(output.content().contains("72"));Tuple Fields§
§0: TTrait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Json<T>where
T: Freeze,
impl<T> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T> Send for Json<T>where
T: Send,
impl<T> Sync for Json<T>where
T: Sync,
impl<T> Unpin for Json<T>where
T: Unpin,
impl<T> UnsafeUnpin for Json<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Json<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more