Skip to content

Commit b534cfd

Browse files
committed
impl Default for KeyspaceId
Signed-off-by: iosmanthus <[email protected]>
1 parent 5efbc12 commit b534cfd

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/request/codec.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ops::{Deref, DerefMut};
12
use tikv_client_common::Error;
23
use tikv_client_proto::{kvrpcpb, metapb::Region};
34

@@ -14,7 +15,7 @@ const RAW_MODE_MAX_KEY: Prefix = [RAW_MODE_PREFIX + 1, 0, 0, 0];
1415
const TXN_MODE_MIN_KEY: Prefix = [TXN_MODE_PREFIX, 0, 0, 0];
1516
const TXN_MODE_MAX_KEY: Prefix = [TXN_MODE_PREFIX + 1, 0, 0, 0];
1617

17-
const MAX_KEYSPACE_ID: KeySpaceId = [0xff, 0xff, 0xff];
18+
const MAX_KEYSPACE_ID: KeySpaceId = KeySpaceId([0xff, 0xff, 0xff]);
1819

1920
pub trait RequestCodec: Sized + Clone + Sync + Send + 'static {
2021
fn encode_key(&self, key: Vec<u8>) -> Vec<u8> {
@@ -150,7 +151,22 @@ impl KeyMode {
150151

151152
type Prefix = [u8; KEYSPACE_PREFIX_LEN];
152153

153-
type KeySpaceId = [u8; 3];
154+
#[derive(Clone,Copy,Default,PartialEq)]
155+
pub struct KeySpaceId([u8; 3]);
156+
157+
impl Deref for KeySpaceId {
158+
type Target = [u8; 3];
159+
160+
fn deref(&self) -> &Self::Target {
161+
&self.0
162+
}
163+
}
164+
165+
impl DerefMut for KeySpaceId {
166+
fn deref_mut(&mut self) -> &mut Self::Target {
167+
&mut self.0
168+
}
169+
}
154170

155171
#[derive(Copy, Clone)]
156172
struct KeySpaceCodec {

0 commit comments

Comments
 (0)