fluvio_sc_schema/objects/
update.rs

1//!
2//! # Update object
3//!
4//!
5
6use std::fmt::Debug;
7
8use anyhow::Result;
9
10use fluvio_protocol::{Encoder, Decoder, Version};
11use fluvio_protocol::api::Request;
12
13use crate::{UpdatableAdminSpec, TryEncodableFrom};
14use crate::Status;
15use crate::AdminPublicApiKey;
16use super::{COMMON_VERSION, TypeBuffer};
17
18#[derive(Debug, Default, Encoder, Decoder)]
19pub struct UpdateRequest<S: UpdatableAdminSpec> {
20    key: S::UpdateKey,
21    pub action: S::UpdateAction,
22}
23
24impl<S> UpdateRequest<S>
25where
26    S: UpdatableAdminSpec,
27{
28    pub fn new(key: S::UpdateKey, action: S::UpdateAction) -> Self {
29        Self { key, action }
30    }
31
32    pub fn with(key: S::UpdateKey, action: S::UpdateAction) -> Self {
33        Self { key, action }
34    }
35
36    pub fn key(self) -> S::UpdateKey {
37        self.key
38    }
39
40    pub fn action(self) -> S::UpdateAction {
41        self.action
42    }
43}
44
45// This can be auto generated by enum derive later
46#[derive(Debug, Default, Encoder, Decoder)]
47pub struct ObjectApiUpdateRequest(TypeBuffer);
48
49impl<S> TryEncodableFrom<UpdateRequest<S>> for ObjectApiUpdateRequest
50where
51    S: UpdatableAdminSpec,
52{
53    fn try_encode_from(input: UpdateRequest<S>, version: Version) -> Result<Self> {
54        Ok(Self(TypeBuffer::encode::<S, _>(input, version)?))
55    }
56
57    fn downcast(&self) -> Result<Option<UpdateRequest<S>>> {
58        self.0.downcast::<S, _>()
59    }
60}
61
62impl Request for ObjectApiUpdateRequest {
63    const API_KEY: u16 = AdminPublicApiKey::Update as u16;
64    const MIN_API_VERSION: i16 = 1; // previous version
65    const DEFAULT_API_VERSION: i16 = COMMON_VERSION;
66    type Response = Status;
67}