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::GptImage1Mini => "gpt-image-1-mini",
54 Self::Other(other) => other,
55 }
56 )
57 }
58}
59
60impl Display for ImageBackground {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 write!(
63 f,
64 "{}",
65 match self {
66 Self::Transparent => "transparent",
67 Self::Opaque => "opaque",
68 Self::Auto => "auto",
69 }
70 )
71 }
72}
73
74impl Display for ImageOutputFormat {
75 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76 write!(
77 f,
78 "{}",
79 match self {
80 Self::Png => "png",
81 Self::Jpeg => "jpeg",
82 Self::Webp => "webp",
83 }
84 )
85 }
86}
87
88impl Display for InputFidelity {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 write!(
91 f,
92 "{}",
93 match self {
94 Self::High => "high",
95 Self::Low => "low",
96 }
97 )
98 }
99}
100
101impl Display for ImageQuality {
102 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103 write!(
104 f,
105 "{}",
106 match self {
107 Self::Low => "low",
108 Self::Medium => "medium",
109 Self::High => "high",
110 Self::Auto => "auto",
111 Self::Standard => "standard",
112 Self::HD => "hd",
113 }
114 )
115 }
116}
117
118impl Display for ImageResponseFormat {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 write!(
121 f,
122 "{}",
123 match self {
124 Self::Url => "url",
125 Self::B64Json => "b64_json",
126 }
127 )
128 }
129}
130
131impl Default for ImageEditInput {
132 fn default() -> Self {
133 Self::Image(ImageInput::default())
134 }
135}
136
137impl From<ImageInput> for ImageEditInput {
138 fn from(value: ImageInput) -> Self {
139 Self::Image(value)
140 }
141}
142
143impl From<Vec<ImageInput>> for ImageEditInput {
144 fn from(value: Vec<ImageInput>) -> Self {
145 Self::Images(value)
146 }
147}
148
149impl From<&str> for ImageEditInput {
151 fn from(value: &str) -> Self {
152 Self::Image(value.into())
153 }
154}
155
156impl From<String> for ImageEditInput {
157 fn from(value: String) -> Self {
158 Self::Image(value.into())
159 }
160}
161
162impl From<&Path> for ImageEditInput {
163 fn from(value: &Path) -> Self {
164 Self::Image(value.into())
165 }
166}
167
168impl From<PathBuf> for ImageEditInput {
169 fn from(value: PathBuf) -> Self {
170 Self::Image(value.into())
171 }
172}
173
174impl<const N: usize> From<[&str; N]> for ImageEditInput {
176 fn from(value: [&str; N]) -> Self {
177 Self::Images(value.into_iter().map(ImageInput::from).collect())
178 }
179}
180
181impl<const N: usize> From<[String; N]> for ImageEditInput {
182 fn from(value: [String; N]) -> Self {
183 Self::Images(value.into_iter().map(ImageInput::from).collect())
184 }
185}
186
187impl<const N: usize> From<[&Path; N]> for ImageEditInput {
188 fn from(value: [&Path; N]) -> Self {
189 Self::Images(value.into_iter().map(ImageInput::from).collect())
190 }
191}
192
193impl<const N: usize> From<[PathBuf; N]> for ImageEditInput {
194 fn from(value: [PathBuf; N]) -> Self {
195 Self::Images(value.into_iter().map(ImageInput::from).collect())
196 }
197}
198
199impl<'a> From<Vec<&'a str>> for ImageEditInput {
201 fn from(value: Vec<&'a str>) -> Self {
202 Self::Images(value.into_iter().map(ImageInput::from).collect())
203 }
204}
205
206impl From<Vec<String>> for ImageEditInput {
207 fn from(value: Vec<String>) -> Self {
208 Self::Images(value.into_iter().map(ImageInput::from).collect())
209 }
210}
211
212impl From<Vec<&Path>> for ImageEditInput {
213 fn from(value: Vec<&Path>) -> Self {
214 Self::Images(value.into_iter().map(ImageInput::from).collect())
215 }
216}
217
218impl From<Vec<PathBuf>> for ImageEditInput {
219 fn from(value: Vec<PathBuf>) -> Self {
220 Self::Images(value.into_iter().map(ImageInput::from).collect())
221 }
222}