Skip to content

Commit 21f4f13

Browse files
committed
Replace into_inner with Into impls
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 6cdb012 commit 21f4f13

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

src/kv.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ impl<'a> fmt::Display for HexRepr<'a> {
6060
pub struct Key(Vec<u8>);
6161

6262
impl Key {
63-
#[inline]
64-
pub(crate) fn into_inner(self) -> Vec<u8> {
65-
self.0
66-
}
67-
6863
#[inline]
6964
fn zero_terminated(&self) -> bool {
7065
self.0.last().map(|i| *i == 0).unwrap_or(false)
@@ -138,6 +133,12 @@ impl AsMut<[u8]> for Key {
138133
}
139134
}
140135

136+
impl Into<Vec<u8>> for Key {
137+
fn into(self) -> Vec<u8> {
138+
self.0
139+
}
140+
}
141+
141142
impl Deref for Key {
142143
type Target = [u8];
143144

@@ -198,13 +199,6 @@ impl fmt::Debug for Key {
198199
#[derive(new, Default, Clone, Eq, PartialEq, Hash)]
199200
pub struct Value(Vec<u8>);
200201

201-
impl Value {
202-
#[inline]
203-
pub(crate) fn into_inner(self) -> Vec<u8> {
204-
self.0
205-
}
206-
}
207-
208202
impl From<Vec<u8>> for Value {
209203
fn from(v: Vec<u8>) -> Self {
210204
Value(v)
@@ -223,6 +217,12 @@ impl From<&'static str> for Value {
223217
}
224218
}
225219

220+
impl Into<Vec<u8>> for Value {
221+
fn into(self) -> Vec<u8> {
222+
self.0
223+
}
224+
}
225+
226226
impl Deref for Value {
227227
type Target = [u8];
228228

@@ -281,11 +281,6 @@ impl KvPair {
281281
&self.1
282282
}
283283

284-
#[inline]
285-
pub fn into_inner(self) -> (Key, Value) {
286-
(self.0, self.1)
287-
}
288-
289284
#[inline]
290285
pub fn into_key(self) -> Key {
291286
self.0
@@ -331,6 +326,12 @@ where
331326
}
332327
}
333328

329+
impl Into<(Key, Value)> for KvPair {
330+
fn into(self) -> (Key, Value) {
331+
(self.0, self.1)
332+
}
333+
}
334+
334335
impl fmt::Debug for KvPair {
335336
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
336337
let KvPair(key, value) = self;

src/rpc/tikv/client.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,20 @@ impl From<Mutation> for kvrpcpb::Mutation {
184184
match mutation {
185185
Mutation::Put(k, v) => {
186186
pb.set_op(kvrpcpb::Op::Put);
187-
pb.set_key(k.into_inner());
188-
pb.set_value(v.into_inner());
187+
pb.set_key(k.into());
188+
pb.set_value(v.into());
189189
}
190190
Mutation::Del(k) => {
191191
pb.set_op(kvrpcpb::Op::Del);
192-
pb.set_key(k.into_inner());
192+
pb.set_key(k.into());
193193
}
194194
Mutation::Lock(k) => {
195195
pb.set_op(kvrpcpb::Op::Lock);
196-
pb.set_key(k.into_inner());
196+
pb.set_key(k.into());
197197
}
198198
Mutation::Rollback(k) => {
199199
pb.set_op(kvrpcpb::Op::Rollback);
200-
pb.set_key(k.into_inner());
200+
pb.set_key(k.into());
201201
}
202202
};
203203
pb
@@ -241,7 +241,7 @@ impl KvClient {
241241
key: Key,
242242
) -> impl Future<Output = Result<kvrpcpb::GetResponse>> {
243243
let mut req = txn_request!(context, kvrpcpb::GetRequest);
244-
req.set_key(key.into_inner());
244+
req.set_key(key.into());
245245
req.set_version(version);
246246

247247
self.execute(request_context(
@@ -262,8 +262,8 @@ impl KvClient {
262262
key_only: bool,
263263
) -> impl Future<Output = Result<kvrpcpb::ScanResponse>> {
264264
let mut req = txn_request!(context, kvrpcpb::ScanRequest);
265-
req.set_start_key(start_key.into_inner());
266-
req.set_end_key(end_key.into_inner());
265+
req.set_start_key(start_key.into());
266+
req.set_end_key(end_key.into());
267267
req.set_version(version);
268268
req.set_limit(limit);
269269
req.set_key_only(key_only);
@@ -287,7 +287,7 @@ impl KvClient {
287287
) -> impl Future<Output = Result<kvrpcpb::PrewriteResponse>> {
288288
let mut req = txn_request!(context, kvrpcpb::PrewriteRequest);
289289
req.set_mutations(mutations.map(Into::into).collect());
290-
req.set_primary_lock(primary_lock.into_inner());
290+
req.set_primary_lock(primary_lock.into());
291291
req.set_start_version(start_version);
292292
req.set_lock_ttl(lock_ttl);
293293
req.set_skip_constraint_check(skip_constraint_check);
@@ -308,7 +308,7 @@ impl KvClient {
308308
commit_version: u64,
309309
) -> impl Future<Output = Result<kvrpcpb::CommitResponse>> {
310310
let mut req = txn_request!(context, kvrpcpb::CommitRequest);
311-
req.set_keys(keys.map(|x| x.into_inner()).collect());
311+
req.set_keys(keys.map(|x| x.into()).collect());
312312
req.set_start_version(start_version);
313313
req.set_commit_version(commit_version);
314314

@@ -344,7 +344,7 @@ impl KvClient {
344344
start_version: u64,
345345
) -> impl Future<Output = Result<kvrpcpb::CleanupResponse>> {
346346
let mut req = txn_request!(context, kvrpcpb::CleanupRequest);
347-
req.set_key(key.into_inner());
347+
req.set_key(key.into());
348348
req.set_start_version(start_version);
349349

350350
self.execute(request_context(
@@ -362,7 +362,7 @@ impl KvClient {
362362
version: u64,
363363
) -> impl Future<Output = Result<kvrpcpb::BatchGetResponse>> {
364364
let mut req = txn_request!(context, kvrpcpb::BatchGetRequest);
365-
req.set_keys(keys.map(|x| x.into_inner()).collect());
365+
req.set_keys(keys.map(|x| x.into()).collect());
366366
req.set_version(version);
367367

368368
self.execute(request_context(
@@ -380,7 +380,7 @@ impl KvClient {
380380
start_version: u64,
381381
) -> impl Future<Output = Result<kvrpcpb::BatchRollbackResponse>> {
382382
let mut req = txn_request!(context, kvrpcpb::BatchRollbackRequest);
383-
req.set_keys(keys.map(|x| x.into_inner()).collect());
383+
req.set_keys(keys.map(|x| x.into()).collect());
384384
req.set_start_version(start_version);
385385

386386
self.execute(request_context(
@@ -400,7 +400,7 @@ impl KvClient {
400400
limit: u32,
401401
) -> impl Future<Output = Result<kvrpcpb::ScanLockResponse>> {
402402
let mut req = txn_request!(context, kvrpcpb::ScanLockRequest);
403-
req.set_start_key(start_key.into_inner());
403+
req.set_start_key(start_key.into());
404404
req.set_max_version(max_version);
405405
req.set_limit(limit);
406406

@@ -456,8 +456,8 @@ impl KvClient {
456456
end_key: Key,
457457
) -> impl Future<Output = Result<kvrpcpb::DeleteRangeResponse>> {
458458
let mut req = txn_request!(context, kvrpcpb::DeleteRangeRequest);
459-
req.set_start_key(start_key.into_inner());
460-
req.set_end_key(end_key.into_inner());
459+
req.set_start_key(start_key.into());
460+
req.set_end_key(end_key.into());
461461

462462
self.execute(request_context(
463463
"kv_delete_range",
@@ -475,7 +475,7 @@ impl KvClient {
475475
key: Key,
476476
) -> impl Future<Output = Result<Value>> {
477477
let mut req = raw_request!(context, cf, kvrpcpb::RawGetRequest);
478-
req.set_key(key.into_inner());
478+
req.set_key(key.into());
479479

480480
self.execute(request_context(
481481
"raw_get",
@@ -493,7 +493,7 @@ impl KvClient {
493493
keys: impl Iterator<Item = Key>,
494494
) -> impl Future<Output = Result<Vec<KvPair>>> {
495495
let mut req = raw_request!(context, cf, kvrpcpb::RawBatchGetRequest);
496-
req.set_keys(keys.map(|x| x.into_inner()).collect());
496+
req.set_keys(keys.map(|x| x.into()).collect());
497497

498498
self.execute(request_context(
499499
"raw_batch_get",
@@ -513,8 +513,8 @@ impl KvClient {
513513
value: Value,
514514
) -> impl Future<Output = Result<()>> {
515515
let mut req = raw_request!(context, cf, kvrpcpb::RawPutRequest);
516-
req.set_key(key.into_inner());
517-
req.set_value(value.into_inner());
516+
req.set_key(key.into());
517+
req.set_value(value.into());
518518

519519
self.execute(request_context(
520520
"raw_put",
@@ -551,7 +551,7 @@ impl KvClient {
551551
key: Key,
552552
) -> impl Future<Output = Result<()>> {
553553
let mut req = raw_request!(context, cf, kvrpcpb::RawDeleteRequest);
554-
req.set_key(key.into_inner());
554+
req.set_key(key.into());
555555

556556
self.execute(request_context(
557557
"raw_delete",
@@ -569,7 +569,7 @@ impl KvClient {
569569
keys: Vec<Key>,
570570
) -> impl Future<Output = Result<()>> {
571571
let mut req = raw_request!(context, cf, kvrpcpb::RawBatchDeleteRequest);
572-
req.set_keys(keys.into_iter().map(|x| x.into_inner()).collect());
572+
req.set_keys(keys.into_iter().map(|x| x.into()).collect());
573573

574574
self.execute(request_context(
575575
"raw_batch_delete",
@@ -591,9 +591,9 @@ impl KvClient {
591591
key_only: bool,
592592
) -> impl Future<Output = Result<Vec<KvPair>>> {
593593
let mut req = raw_request!(context, cf, kvrpcpb::RawScanRequest);
594-
req.set_start_key(start_key.into_inner());
594+
req.set_start_key(start_key.into());
595595
// FIXME we shouldn't panic when there is no end_key
596-
end_key.map(|k| req.set_end_key(k.into_inner())).unwrap();
596+
end_key.map(|k| req.set_end_key(k.into())).unwrap();
597597
req.set_limit(limit);
598598
req.set_key_only(key_only);
599599

@@ -637,8 +637,8 @@ impl KvClient {
637637
end_key: Key,
638638
) -> impl Future<Output = Result<()>> {
639639
let mut req = raw_request!(context, cf, kvrpcpb::RawDeleteRangeRequest);
640-
req.set_start_key(start_key.into_inner());
641-
req.set_end_key(end_key.into_inner());
640+
req.set_start_key(start_key.into());
641+
req.set_end_key(end_key.into());
642642

643643
self.execute(request_context(
644644
"raw_delete_range",
@@ -683,9 +683,9 @@ impl KvClient {
683683
#[inline]
684684
fn convert_to_grpc_pair(pair: KvPair) -> kvrpcpb::KvPair {
685685
let mut result = kvrpcpb::KvPair::default();
686-
let (key, value) = pair.into_inner();
687-
result.set_key(key.into_inner());
688-
result.set_value(value.into_inner());
686+
let (key, value) = pair.into();
687+
result.set_key(key.into());
688+
result.set_value(value.into());
689689
result
690690
}
691691

@@ -711,8 +711,8 @@ impl KvClient {
711711
fn convert_to_grpc_range(range: (Option<Key>, Option<Key>)) -> kvrpcpb::KeyRange {
712712
let (start, end) = range;
713713
let mut range = kvrpcpb::KeyRange::default();
714-
start.map(|k| range.set_start_key(k.into_inner())).unwrap();
715-
end.map(|k| range.set_end_key(k.into_inner())).unwrap();
714+
start.map(|k| range.set_start_key(k.into())).unwrap();
715+
end.map(|k| range.set_end_key(k.into())).unwrap();
716716
range
717717
}
718718

0 commit comments

Comments
 (0)