openstack_sdk 0.22.5

OpenStack SDK
Documentation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.
use derive_builder::Builder;
use http::{HeaderMap, HeaderName, HeaderValue};

use crate::api::find::Findable;
use crate::api::rest_endpoint_prelude::*;
use crate::api::{ApiError, RestClient};

use crate::api::load_balancer::v2::pool::{get as Get, list as List};

/// Find for pool by nameOrId.
#[derive(Debug, Builder, Clone)]
#[builder(setter(strip_option))]
pub struct Request<'a> {
    #[builder(setter(into), default)]
    id: Cow<'a, str>,

    #[builder(setter(name = "_headers"), default, private)]
    _headers: Option<HeaderMap>,
}

impl<'a> Request<'a> {
    /// Create a builder for the endpoint.
    pub fn builder() -> RequestBuilder<'a> {
        RequestBuilder::default()
    }
}

impl<'a> RequestBuilder<'a> {
    /// Add a single header to the Volume.
    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
    where
        K: Into<HeaderName>,
        V: Into<HeaderValue>,
    {
        self._headers
            .get_or_insert(None)
            .get_or_insert_with(HeaderMap::new)
            .insert(header_name.into(), header_value.into());
        self
    }

    /// Add multiple headers.
    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
    where
        I: Iterator<Item = T>,
        T: Into<(Option<HeaderName>, HeaderValue)>,
    {
        self._headers
            .get_or_insert(None)
            .get_or_insert_with(HeaderMap::new)
            .extend(iter.map(Into::into));
        self
    }
}

impl<'a> Findable for Request<'a> {
    type G = Get::Request<'a>;
    type L = List::Request<'a>;
    fn get_ep<C: RestClient>(&self) -> Result<Get::Request<'a>, ApiError<C::Error>> {
        let mut ep = Get::Request::builder();
        ep.id(self.id.clone());
        if let Some(headers) = &self._headers {
            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
        }
        ep.build().map_err(ApiError::endpoint_builder)
    }

    fn list_ep<C: RestClient>(&self) -> Result<List::Request<'a>, ApiError<C::Error>> {
        let mut ep = List::Request::builder();
        if let Some(headers) = &self._headers {
            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
        }
        ep.name(self.id.clone());
        ep.build().map_err(ApiError::endpoint_builder)
    }
}