Skip to content

Commit c5eb7d4

Browse files
committed
Make ColumnFamily a little more opaque
Derived from #58 Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 6615d3d commit c5eb7d4

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

src/raw.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
//!
1212
use crate::{rpc::RpcClient, Config, Error, Key, KeyRange, KvPair, Result, Value};
1313
use futures::{future, task::Context, Future, Poll};
14-
use std::{
15-
ops::{Bound, Deref},
16-
pin::Pin,
17-
sync::Arc,
18-
u32,
19-
};
14+
use std::{fmt, ops::Bound, pin::Pin, sync::Arc, u32};
2015

2116
const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240;
2217

@@ -310,33 +305,21 @@ impl Future for Connect {
310305
/// let cf = ColumnFamily::from(&String::from("write"));
311306
/// ```
312307
///
313-
/// This is a *wrapper type* that implements `Deref<Target=String>` so it can be used like one transparently.
314-
///
315308
/// **But, you should not need to worry about all this:** Many functions which accept a
316309
/// `ColumnFamily` accept an `Into<ColumnFamily>`, which means all of the above types can be passed
317310
/// directly to those functions.
318311
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
319312
pub struct ColumnFamily(String);
320313

321-
impl<T> From<T> for ColumnFamily
322-
where
323-
T: ToString,
324-
{
314+
impl<T: Into<String>> From<T> for ColumnFamily {
325315
fn from(i: T) -> ColumnFamily {
326-
ColumnFamily(i.to_string())
327-
}
328-
}
329-
330-
impl ColumnFamily {
331-
pub fn into_inner(self) -> String {
332-
self.0
316+
ColumnFamily(i.into())
333317
}
334318
}
335319

336-
impl Deref for ColumnFamily {
337-
type Target = String;
338-
fn deref(&self) -> &Self::Target {
339-
&self.0
320+
impl fmt::Display for ColumnFamily {
321+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
322+
self.0.fmt(f)
340323
}
341324
}
342325

src/rpc/tikv/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ macro_rules! raw_request {
165165
let (region, cf) = $context.into_inner();
166166
req.set_context(region.into());
167167
if let Some(cf) = cf {
168-
req.set_cf(cf.into_inner());
168+
req.set_cf(cf.to_string());
169169
}
170170
req
171171
}};

0 commit comments

Comments
 (0)