Skip to content

Commit

Permalink
feat(data): impl Data for &Data
Browse files Browse the repository at this point in the history
This implements Data for every reference of something that already implements Data
  • Loading branch information
SebastianSpeitel committed Jan 24, 2024
1 parent 70a5a21 commit 225746b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
24 changes: 24 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ pub trait Data {
}
}

#[warn(clippy::missing_trait_methods)]
impl<D: Data + ?Sized> Data for &D {
#[inline]
fn provide_value<'d>(&'d self, builder: &mut dyn ValueBuiler<'d>) {
(*self).provide_value(builder)
}
#[inline]
fn provide_links(&self, links: &mut dyn Links) -> Result<(), LinkError> {
(*self).provide_links(links)
}
#[inline]
fn query_links(
&self,
links: &mut dyn Links,
query: &crate::query::Query,
) -> Result<(), LinkError> {
(*self).query_links(links, query)
}
#[inline]
fn get_id(&self) -> Option<crate::id::ID> {
(*self).get_id()
}
}

#[cfg(feature = "unique")]
impl<D: Data + ?Sized> PartialEq<D> for dyn Data {
#[inline]
Expand Down
24 changes: 0 additions & 24 deletions src/data/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,6 @@ mod std;
#[cfg(feature = "toml")]
mod toml;

#[warn(clippy::missing_trait_methods)]
impl Data for &dyn Data {
#[inline]
fn provide_value<'d>(&'d self, builder: &mut dyn ValueBuiler<'d>) {
(**self).provide_value(builder)
}
#[inline]
fn provide_links(&self, links: &mut dyn Links) -> Result<(), LinkError> {
(**self).provide_links(links)
}
#[inline]
fn query_links(
&self,
links: &mut dyn Links,
query: &crate::query::Query,
) -> Result<(), LinkError> {
(**self).query_links(links, query)
}
#[inline]
fn get_id(&self) -> Option<ID> {
(**self).get_id()
}
}

#[warn(clippy::missing_trait_methods)]
impl<D: Data + ?Sized> Data for Box<D> {
#[inline]
Expand Down
14 changes: 0 additions & 14 deletions src/data/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ impl Data for str {
}
}

impl Data for &str {
#[inline]
fn provide_value<'d>(&'d self, value: &mut dyn ValueBuiler<'d>) {
value.str(Cow::Borrowed(self));
}
}

impl Data for char {
#[inline]
fn provide_value<'d>(&'d self, value: &mut dyn ValueBuiler<'d>) {
Expand All @@ -44,13 +37,6 @@ impl Data for [u8] {
}
}

impl Data for &[u8] {
#[inline]
fn provide_value<'d>(&'d self, value: &mut dyn ValueBuiler<'d>) {
value.bytes(Cow::Borrowed(self));
}
}

mod path {
use super::*;
#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 225746b

Please sign in to comment.