gemini_genai_rs/session/
traits.rs1use super::errors::SessionError;
7use super::events::SessionEvent;
8use super::state::SessionPhase;
9use crate::protocol::{Content, FunctionResponse};
10use async_trait::async_trait;
11use tokio::sync::broadcast;
12
13#[async_trait]
15pub trait SessionWriter: Send + Sync + 'static {
16 async fn send_audio(&self, data: Vec<u8>) -> Result<(), SessionError>;
18 async fn send_text(&self, text: String) -> Result<(), SessionError>;
20 async fn send_tool_response(
22 &self,
23 responses: Vec<FunctionResponse>,
24 ) -> Result<(), SessionError>;
25 async fn send_client_content(
27 &self,
28 turns: Vec<Content>,
29 turn_complete: bool,
30 ) -> Result<(), SessionError>;
31 async fn send_video(&self, jpeg_data: Vec<u8>) -> Result<(), SessionError>;
33 async fn update_instruction(&self, instruction: String) -> Result<(), SessionError>;
35 async fn signal_activity_start(&self) -> Result<(), SessionError>;
37 async fn signal_activity_end(&self) -> Result<(), SessionError>;
39 async fn disconnect(&self) -> Result<(), SessionError>;
41}
42
43pub trait SessionReader: Send + Sync + 'static {
45 fn subscribe(&self) -> broadcast::Receiver<SessionEvent>;
47 fn phase(&self) -> SessionPhase;
49 fn session_id(&self) -> &str;
51}
52
53#[cfg(test)]
54mod tests {
55 use super::super::handle::SessionHandle;
56 use super::*;
57
58 #[test]
59 fn session_handle_implements_session_writer() {
60 fn assert_impl<T: SessionWriter>() {}
61 assert_impl::<SessionHandle>();
62 }
63
64 #[test]
65 fn session_handle_implements_session_reader() {
66 fn assert_impl<T: SessionReader>() {}
67 assert_impl::<SessionHandle>();
68 }
69
70 #[test]
71 fn session_writer_is_object_safe() {
72 fn _assert(_: &dyn SessionWriter) {}
73 }
74
75 #[test]
76 fn session_reader_is_object_safe() {
77 fn _assert(_: &dyn SessionReader) {}
78 }
79}