d_engine/proto/
client_extensions.rs

1//! Extensions for protobuf-generated client types
2//!
3//! This module provides additional methods for protobuf-generated types
4//! that are not automatically generated by the protobuf compiler.
5
6use crate::proto::client::ClientReadRequest;
7use crate::proto::client::ReadConsistencyPolicy;
8
9impl ClientReadRequest {
10    /// Checks if the consistency_policy field is present in the request
11    ///
12    /// Returns true if the client explicitly specified a consistency policy,
13    /// false if the field is absent (should use server default).
14    pub fn has_consistency_policy(&self) -> bool {
15        self.consistency_policy.is_some()
16    }
17
18    /// Gets the consistency policy value safely
19    ///
20    /// Returns Some(policy) if present, None if field is absent.
21    /// Safer alternative that doesn't panic.
22    pub fn get_consistency_policy(&self) -> Option<ReadConsistencyPolicy> {
23        self.consistency_policy.and_then(|policy_i32| {
24            match policy_i32 {
25                x if x == ReadConsistencyPolicy::LeaseRead as i32 => {
26                    Some(ReadConsistencyPolicy::LeaseRead)
27                }
28                x if x == ReadConsistencyPolicy::LinearizableRead as i32 => {
29                    Some(ReadConsistencyPolicy::LinearizableRead)
30                }
31                _ => None, // Invalid value
32            }
33        })
34    }
35}