Skip to main content

openstack_keystone_distributed_storage/proto_impl/
impl_admin_response.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14use crate::types::ClientWriteResponse;
15use crate::{StoreError, pb};
16
17impl TryFrom<pb::raft::AdminResponse> for ClientWriteResponse {
18    type Error = StoreError;
19    fn try_from(r: pb::raft::AdminResponse) -> Result<Self, Self::Error> {
20        Ok(ClientWriteResponse {
21            log_id: r
22                .log_id
23                .ok_or_else(|| StoreError::RaftMissingParameter("AdminResponse.LogId".into()))?
24                .into(),
25            data: r.data.unwrap_or_default(),
26            membership: r.membership.map(|mem| mem.try_into()).transpose()?,
27        })
28    }
29}
30
31impl From<ClientWriteResponse> for pb::raft::AdminResponse {
32    fn from(r: ClientWriteResponse) -> Self {
33        pb::raft::AdminResponse {
34            log_id: Some(r.log_id.into()),
35            data: Some(r.data),
36            membership: r.membership.map(|mem| mem.into()),
37        }
38    }
39}