Skip to content

Commit

Permalink
Elide explicit parameter types lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Jan 6, 2021
1 parent 3bab308 commit 7b4883b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/storage-plus/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait PrimaryKey<'a>: Clone {
type SubPrefix: Prefixer<'a>;

/// returns a slice of key steps, which can be optionally combined
fn key<'b>(&'b self) -> Vec<&'b [u8]>;
fn key(&self) -> Vec<&[u8]>;

fn joined_key(&self) -> Vec<u8> {
let keys = self.key();
Expand All @@ -27,7 +27,7 @@ impl<'a> PrimaryKey<'a> for &'a [u8] {
type Prefix = ();
type SubPrefix = ();

fn key<'b>(&'b self) -> Vec<&'b [u8]> {
fn key(&self) -> Vec<&[u8]> {
// this is simple, we don't add more prefixes
vec![self]
}
Expand All @@ -42,7 +42,7 @@ impl<'a> PrimaryKey<'a> for &'a str {
type Prefix = ();
type SubPrefix = ();

fn key<'b>(&'b self) -> Vec<&'b [u8]> {
fn key(&self) -> Vec<&[u8]> {
// this is simple, we don't add more prefixes
vec![self.as_bytes()]
}
Expand All @@ -57,7 +57,7 @@ impl<'a, T: PrimaryKey<'a> + Prefixer<'a>, U: PrimaryKey<'a>> PrimaryKey<'a> for
type Prefix = T;
type SubPrefix = ();

fn key<'b>(&'b self) -> Vec<&'b [u8]> {
fn key(&self) -> Vec<&[u8]> {
let mut keys = self.0.key();
keys.extend(&self.1.key());
keys
Expand Down Expand Up @@ -102,15 +102,15 @@ impl<'a, T: PrimaryKey<'a> + Prefixer<'a>, U: PrimaryKey<'a> + Prefixer<'a>, V:
// pub trait Prefixer<'a>: Copy {
pub trait Prefixer<'a> {
/// returns 0 or more namespaces that should length-prefixed and concatenated for range searches
fn prefix<'b>(&'b self) -> Vec<&'b [u8]>;
fn prefix(&self) -> Vec<&[u8]>;

/// returns 0 or 1 less than prefix() namespaces that should length-prefixed and concatenated
/// for range searches
fn sub_prefix(&self) -> Vec<&[u8]>;
}

impl<'a> Prefixer<'a> for () {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
vec![]
}

Expand All @@ -120,7 +120,7 @@ impl<'a> Prefixer<'a> for () {
}

impl<'a> Prefixer<'a> for &'a [u8] {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
vec![self]
}

Expand All @@ -130,7 +130,7 @@ impl<'a> Prefixer<'a> for &'a [u8] {
}

impl<'a, T: Prefixer<'a>, U: Prefixer<'a>> Prefixer<'a> for (T, U) {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
let mut res = self.0.prefix();
res.extend(self.1.prefix().into_iter());
res
Expand All @@ -142,7 +142,7 @@ impl<'a, T: Prefixer<'a>, U: Prefixer<'a>> Prefixer<'a> for (T, U) {
}

impl<'a, T: Prefixer<'a>, U: Prefixer<'a>, V: Prefixer<'a>> Prefixer<'a> for (T, U, V) {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
let mut res = self.0.prefix();
res.extend(self.1.prefix().into_iter());
res.extend(self.2.prefix().into_iter());
Expand All @@ -158,7 +158,7 @@ impl<'a, T: Prefixer<'a>, U: Prefixer<'a>, V: Prefixer<'a>> Prefixer<'a> for (T,

// Provide a string version of this to raw encode strings
impl<'a> Prefixer<'a> for &'a str {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
vec![self.as_bytes()]
}

Expand All @@ -184,7 +184,7 @@ impl<'a> PrimaryKey<'a> for PkOwned {
type Prefix = ();
type SubPrefix = ();

fn key<'b>(&'b self) -> Vec<&'b [u8]> {
fn key(&self) -> Vec<&[u8]> {
vec![&self.0]
}

Expand All @@ -194,7 +194,7 @@ impl<'a> PrimaryKey<'a> for PkOwned {
}

impl<'a> Prefixer<'a> for PkOwned {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
vec![&self.0]
}

Expand All @@ -208,7 +208,7 @@ impl<'a, T: AsRef<PkOwned> + From<PkOwned> + Clone> PrimaryKey<'a> for T {
type Prefix = ();
type SubPrefix = ();

fn key<'b>(&'b self) -> Vec<&'b [u8]> {
fn key(&self) -> Vec<&[u8]> {
self.as_ref().key()
}

Expand All @@ -219,7 +219,7 @@ impl<'a, T: AsRef<PkOwned> + From<PkOwned> + Clone> PrimaryKey<'a> for T {

// this auto-implements Prefixer for all the IntKey types (and more!)
impl<'a, T: AsRef<PkOwned>> Prefixer<'a> for T {
fn prefix<'b>(&'b self) -> Vec<&'b [u8]> {
fn prefix(&self) -> Vec<&[u8]> {
self.as_ref().prefix()
}

Expand Down

0 comments on commit 7b4883b

Please sign in to comment.