Skip to content

Commit

Permalink
improve convertability of data into Key
Browse files Browse the repository at this point in the history
  • Loading branch information
chpio committed Mar 9, 2017
1 parent 7c07252 commit 1e0965f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vtree/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::{self, Write};
use std::rc::Rc;
use std::convert::{From, Into};
use std::borrow::Borrow;

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum Key {
Expand Down Expand Up @@ -39,6 +40,12 @@ impl From<String> for Key {
}
}

impl From<Rc<String>> for Key {
fn from(v: Rc<String>) -> Key {
Key::String(v)
}
}

impl From<&'static str> for Key {
fn from(v: &'static str) -> Key {
Key::Str(v)
Expand All @@ -51,6 +58,21 @@ impl From<Vec<u8>> for Key {
}
}

impl From<Rc<Vec<u8>>> for Key {
fn from(v: Rc<Vec<u8>>) -> Key {
Key::Bytes(v)
}
}

impl<'a, T, O> From<&'a T> for Key
where T: ToOwned<Owned=O> + ?Sized,
O: Borrow<T> + Into<Key>
{
default fn from(v: &'a T) -> Key {
v.to_owned().into()
}
}

pub fn key<T: Into<Key>>(key: T) -> Key {
key.into()
}
Expand Down
1 change: 1 addition & 0 deletions vtree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(conservative_impl_trait)]
#![feature(specialization)]

extern crate ordermap;
extern crate itertools;
Expand Down

0 comments on commit 1e0965f

Please sign in to comment.