aerospike/batch/
batch_read.rs

1// Copyright 2015-2018 Aerospike, Inc.
2//
3// Portions may be licensed to Aerospike, Inc. under one or more contributor
4// license agreements.
5//
6// Licensed under the Apache License, Version 2.0 (the "License"); you may not
7// use this file except in compliance with the License. You may obtain a copy of
8// the License at http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13// License for the specific language governing permissions and limitations under
14// the License.
15
16use crate::Bins;
17use crate::Key;
18use crate::Record;
19#[cfg(feature = "serialization")]
20use serde::Serialize;
21
22/// Key and bin names used in batch read commands where variable bins are needed for each key.
23#[cfg_attr(feature = "serialization", derive(Serialize))]
24pub struct BatchRead<'a> {
25    /// Key.
26    pub key: Key,
27
28    /// Bins to retrieve for this key.
29    pub bins: &'a Bins,
30
31    /// Will contain the record after the batch read operation.
32    pub record: Option<Record>,
33}
34
35impl<'a> BatchRead<'a> {
36    /// Create a new `BatchRead` instance for the given key and bin selector.
37    pub const fn new(key: Key, bins: &'a Bins) -> Self {
38        BatchRead {
39            key,
40            bins,
41            record: None,
42        }
43    }
44
45    #[doc(hidden)]
46    pub fn match_header(&self, other: &BatchRead<'a>, match_set: bool) -> bool {
47        let key = &self.key;
48        let other_key = &other.key;
49        (key.namespace == other_key.namespace)
50            && (match_set && (key.set_name == other_key.set_name))
51            && (self.bins == other.bins)
52    }
53}