amazon_rekognition/api/actions/
detect_labels.rs

1//! https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectLabels.html
2//! https://docs.aws.amazon.com/rekognition/latest/dg/labels-detect-labels-image.html
3
4use serde::{Deserialize, Serialize};
5
6use crate::{
7    api::data_types::{Image, Label},
8    ServiceEndpoint,
9};
10
11use super::Action;
12
13pub const OPERATION_NAME: &str = "DetectLabels";
14
15pub fn new<'a>(
16    access_key_id: &'a str,
17    secret_access_key: &'a str,
18    service_endpoint: ServiceEndpoint<'a>,
19    request_body: DetectLabelsRequestBody,
20) -> Action<'a, DetectLabelsRequestBody, DetectLabelsResponseOkBody> {
21    Action::new(
22        access_key_id,
23        secret_access_key,
24        service_endpoint,
25        request_body,
26        OPERATION_NAME,
27    )
28}
29
30#[derive(Serialize, Deserialize, Debug, Clone)]
31#[serde(rename_all = "PascalCase")]
32pub struct DetectLabelsRequestBody {
33    pub image: Image,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub max_labels: Option<usize>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub min_confidence: Option<f64>,
38}
39
40#[derive(Serialize, Deserialize, Debug, Clone)]
41#[serde(rename_all = "PascalCase")]
42pub struct DetectLabelsResponseOkBody {
43    pub label_model_version: String,
44    pub labels: Vec<Label>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub orientation_correction: Option<String>,
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn de_response_ok_body() {
55        match serde_json::from_str::<DetectLabelsResponseOkBody>(include_str!(
56            "../../../tests/response_body_json_files/detect_labels_ok.json"
57        )) {
58            Ok(ok_json) => {
59                assert_eq!(ok_json.labels.len(), 13);
60            }
61            Err(err) => panic!("{}", err),
62        }
63    }
64}