async_openai/types/images/
impls.rs1use std::{
2 fmt::Display,
3 path::{Path, PathBuf},
4};
5
6use crate::types::images::{
7 DallE2ImageSize, ImageBackground, ImageEditInput, ImageInput, ImageModel, ImageOutputFormat,
8 ImageQuality, ImageResponseFormat, ImageSize, InputFidelity,
9};
10
11impl Display for ImageSize {
12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 write!(
14 f,
15 "{}",
16 match self {
17 Self::S256x256 => "256x256",
18 Self::S512x512 => "512x512",
19 Self::S1024x1024 => "1024x1024",
20 Self::S1792x1024 => "1792x1024",
21 Self::S1024x1792 => "1024x1792",
22 Self::S1536x1024 => "1536x1024",
23 Self::S1024x1536 => "1024x1536",
24 Self::Auto => "auto",
25 }
26 )
27 }
28}
29
30impl Display for DallE2ImageSize {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(
33 f,
34 "{}",
35 match self {
36 Self::S256x256 => "256x256",
37 Self::S512x512 => "512x512",
38 Self::S1024x1024 => "1024x1024",
39 }
40 )
41 }
42}
43
44impl Display for ImageModel {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 write!(
47 f,
48 "{}",
49 match self {
50 Self::DallE2 => "dall-e-2",
51 Self::DallE3 => "dall-e-3",
52 Self::GptImage1 => "gpt-image-1",
53 Self::GptImage1dot5 => "gpt-image-1.5",
54 Self::GptImage1Mini => "gpt-image-1-mini",
55 Self::Other(other) => other,
56 }
57 )
58 }
59}
60
61impl Display for ImageBackground {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 write!(
64 f,
65 "{}",
66 match self {
67 Self::Transparent => "transparent",
68 Self::Opaque => "opaque",
69 Self::Auto => "auto",
70 }
71 )
72 }
73}
74
75impl Display for ImageOutputFormat {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 write!(
78 f,
79 "{}",
80 match self {
81 Self::Png => "png",
82 Self::Jpeg => "jpeg",
83 Self::Webp => "webp",
84 }
85 )
86 }
87}
88
89impl Display for InputFidelity {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 write!(
92 f,
93 "{}",
94 match self {
95 Self::High => "high",
96 Self::Low => "low",
97 }
98 )
99 }
100}
101
102impl Display for ImageQuality {
103 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 write!(
105 f,
106 "{}",
107 match self {
108 Self::Low => "low",
109 Self::Medium => "medium",
110 Self::High => "high",
111 Self::Auto => "auto",
112 Self::Standard => "standard",
113 Self::HD => "hd",
114 }
115 )
116 }
117}
118
119impl Display for ImageResponseFormat {
120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121 write!(
122 f,
123 "{}",
124 match self {
125 Self::Url => "url",
126 Self::B64Json => "b64_json",
127 }
128 )
129 }
130}
131
132impl Default for ImageEditInput {
133 fn default() -> Self {
134 Self::Image(ImageInput::default())
135 }
136}
137
138impl From<ImageInput> for ImageEditInput {
139 fn from(value: ImageInput) -> Self {
140 Self::Image(value)
141 }
142}
143
144impl From<Vec<ImageInput>> for ImageEditInput {
145 fn from(value: Vec<ImageInput>) -> Self {
146 Self::Images(value)
147 }
148}
149
150impl From<&str> for ImageEditInput {
152 fn from(value: &str) -> Self {
153 Self::Image(value.into())
154 }
155}
156
157impl From<String> for ImageEditInput {
158 fn from(value: String) -> Self {
159 Self::Image(value.into())
160 }
161}
162
163impl From<&Path> for ImageEditInput {
164 fn from(value: &Path) -> Self {
165 Self::Image(value.into())
166 }
167}
168
169impl From<PathBuf> for ImageEditInput {
170 fn from(value: PathBuf) -> Self {
171 Self::Image(value.into())
172 }
173}
174
175impl<const N: usize> From<[&str; N]> for ImageEditInput {
177 fn from(value: [&str; N]) -> Self {
178 Self::Images(value.into_iter().map(ImageInput::from).collect())
179 }
180}
181
182impl<const N: usize> From<[String; N]> for ImageEditInput {
183 fn from(value: [String; N]) -> Self {
184 Self::Images(value.into_iter().map(ImageInput::from).collect())
185 }
186}
187
188impl<const N: usize> From<[&Path; N]> for ImageEditInput {
189 fn from(value: [&Path; N]) -> Self {
190 Self::Images(value.into_iter().map(ImageInput::from).collect())
191 }
192}
193
194impl<const N: usize> From<[PathBuf; N]> for ImageEditInput {
195 fn from(value: [PathBuf; N]) -> Self {
196 Self::Images(value.into_iter().map(ImageInput::from).collect())
197 }
198}
199
200impl<'a> From<Vec<&'a str>> for ImageEditInput {
202 fn from(value: Vec<&'a str>) -> Self {
203 Self::Images(value.into_iter().map(ImageInput::from).collect())
204 }
205}
206
207impl From<Vec<String>> for ImageEditInput {
208 fn from(value: Vec<String>) -> Self {
209 Self::Images(value.into_iter().map(ImageInput::from).collect())
210 }
211}
212
213impl From<Vec<&Path>> for ImageEditInput {
214 fn from(value: Vec<&Path>) -> Self {
215 Self::Images(value.into_iter().map(ImageInput::from).collect())
216 }
217}
218
219impl From<Vec<PathBuf>> for ImageEditInput {
220 fn from(value: Vec<PathBuf>) -> Self {
221 Self::Images(value.into_iter().map(ImageInput::from).collect())
222 }
223}