1use reqwest::header::HeaderMap;
2use serde::Serialize;
3
4use crate::RequestOptions;
5use crate::error::OpenAIError;
6
7pub trait AsyncTryFrom<T>: Sized {
8 type Error;
10
11 fn try_from(value: T) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
13}
14
15pub trait EventType {
17 fn event_type(&self) -> &'static str;
19}
20
21pub trait EventId {
23 fn event_id(&self) -> &str;
25}
26
27pub trait RequestOptionsBuilder: Sized {
29 fn options_mut(&mut self) -> &mut RequestOptions;
31
32 fn options(&self) -> &RequestOptions;
34
35 fn headers(mut self, headers: HeaderMap) -> Self {
37 self.options_mut().with_headers(headers);
38 self
39 }
40
41 fn header<K, V>(mut self, key: K, value: V) -> Result<Self, OpenAIError>
43 where
44 K: reqwest::header::IntoHeaderName,
45 V: TryInto<reqwest::header::HeaderValue>,
46 V::Error: Into<reqwest::header::InvalidHeaderValue>,
47 {
48 self.options_mut().with_header(key, value)?;
49 Ok(self)
50 }
51
52 fn query<Q: Serialize + ?Sized>(mut self, query: &Q) -> Result<Self, OpenAIError> {
54 self.options_mut().with_query(query)?;
55 Ok(self)
56 }
57
58 fn path<P: Into<String>>(mut self, path: P) -> Result<Self, OpenAIError> {
60 self.options_mut().with_path(path.into().as_str())?;
61 Ok(self)
62 }
63}