google_cloud_vision_rest/v1/types/
annotate_image_request.rs1use base64::{engine::general_purpose, Engine as _};
4use serde::{Deserialize, Serialize};
5
6use super::{Feature, ImageContext};
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct AnnotateImageRequest {
11 pub image: Image,
12 pub features: Vec<Feature>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub image_context: Option<ImageContext>,
15}
16
17#[derive(Serialize, Deserialize, Debug, Clone)]
18#[serde(rename_all = "camelCase")]
19pub struct Image {
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub content: Option<String>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub source: Option<ImageSource>,
24}
25impl Image {
26 pub fn with_bytes(binary_data: Vec<u8>) -> Self {
27 Self {
28 content: Some(general_purpose::STANDARD.encode(binary_data)),
29 source: None,
30 }
31 }
32 pub fn with_url(url: String) -> Self {
33 Self {
34 content: None,
35 source: Some(ImageSource {
36 gcs_image_uri: None,
37 image_uri: Some(url),
38 }),
39 }
40 }
41}
42
43#[derive(Serialize, Deserialize, Debug, Clone)]
44#[serde(rename_all = "camelCase")]
45pub struct ImageSource {
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub gcs_image_uri: Option<String>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub image_uri: Option<String>,
50}