objectiveai_sdk/functions/executions/
retry_token.rs1use base64::Engine;
4use serde::{Deserialize, Serialize};
5use schemars::JsonSchema;
6
7#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
12#[serde(transparent)]
13#[schemars(!transparent)]
14#[schemars(rename = "functions.executions.RetryToken")]
15pub struct RetryToken(pub Vec<Option<String>>);
16
17impl RetryToken {
18 pub fn clone_slice(&self, range: std::ops::Range<usize>) -> Self {
19 let len = range.end.saturating_sub(range.start);
20 let mut out = Vec::with_capacity(len);
21 for i in range.start..range.end {
22 out.push(self.0.get(i).cloned().unwrap_or(None));
23 }
24 RetryToken(out)
25 }
26
27 pub fn push(&mut self, other: RetryToken) {
29 self.0.extend(other.0)
30 }
31
32 pub fn insert(&mut self, index: usize, other: RetryToken) {
34 for (i, token) in other.0.into_iter().enumerate() {
35 self.0[index + i] = token;
36 }
37 }
38
39 pub fn to_string(&self) -> String {
41 let json = serde_json::to_string(self).unwrap();
42 base64::engine::general_purpose::STANDARD.encode(json)
43 }
44
45 pub fn try_from_string(s: &str) -> Option<Self> {
47 let json = base64::engine::general_purpose::STANDARD.decode(s).ok()?;
48 let token = serde_json::from_slice(&json).ok()?;
49 Some(token)
50 }
51}