Skip to content

Commit

Permalink
Merge pull request #2 from SebastianSpeitel/more-lints
Browse files Browse the repository at this point in the history
chore: more lints
  • Loading branch information
SebastianSpeitel authored Jan 14, 2024
2 parents 722862e + 8ac0968 commit 2321346
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl<D: Data + ?Sized> PartialEq<D> for dyn Data {
}

impl Debug for dyn Data {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.format::<format::DEBUG>().fmt(f)
}
Expand Down
1 change: 1 addition & 0 deletions src/data/ext.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use std::borrow::Cow;

use crate::data::{format, BoxedData, Data};
Expand Down
19 changes: 19 additions & 0 deletions src/data/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub type DEBUG = FORMAT<true, 6, false>;
pub trait DataFormatter {
type State: Default + Copy;

#[inline]
#[must_use]
fn init_state() -> Self::State {
Default::default()
}
Expand Down Expand Up @@ -212,12 +214,14 @@ impl<'d, F: DataFormatter, D: Data + ?Sized> From<&'d D> for FormattableData<'d,
}

impl<F: DataFormatter, D: Data + ?Sized> Display for FormattableData<'_, F, D> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
F::fmt(f, self.data, F::init_state())
}
}

impl<F: DataFormatter, D: Data + ?Sized> Debug for FormattableData<'_, F, D> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
F::fmt(f, self.data, F::init_state())
}
Expand Down Expand Up @@ -393,49 +397,64 @@ mod serial {

#[warn(clippy::missing_trait_methods)]
impl ValueBuiler<'_> for fmt::DebugStruct<'_, '_> {
#[inline]
fn bool(&mut self, value: bool) {
self.field("bool", &value);
}
#[inline]
fn u8(&mut self, value: u8) {
self.field("u8", &value);
}
#[inline]
fn i8(&mut self, value: i8) {
self.field("i8", &value);
}
#[inline]
fn u16(&mut self, value: u16) {
self.field("u16", &value);
}
#[inline]
fn i16(&mut self, value: i16) {
self.field("i16", &value);
}
#[inline]
fn u32(&mut self, value: u32) {
self.field("u32", &value);
}
#[inline]
fn i32(&mut self, value: i32) {
self.field("i32", &value);
}
#[inline]
fn u64(&mut self, value: u64) {
self.field("u64", &value);
}
#[inline]
fn i64(&mut self, value: i64) {
self.field("i64", &value);
}
#[inline]
fn u128(&mut self, value: u128) {
self.field("u128", &value);
}
#[inline]
fn i128(&mut self, value: i128) {
self.field("i128", &value);
}
#[inline]
fn f32(&mut self, value: f32) {
self.field("f32", &value);
}
#[inline]
fn f64(&mut self, value: f64) {
self.field("f64", &value);
}
#[inline]
fn str(&mut self, value: Cow<'_, str>) {
let value: &str = &value;
self.field("str", &value);
}
#[inline]
fn bytes(&mut self, value: Cow<'_, [u8]>) {
match String::from_utf8(value.to_vec()) {
Ok(s) => self.field("bytes", &format_args!("b{s:?}")),
Expand Down
2 changes: 0 additions & 2 deletions src/data/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl Data for &dyn Data {
(**self).query_links(builder, query)
}
#[inline]
#[cfg(feature = "unique")]
fn get_id(&self) -> Option<ID> {
(**self).get_id()
}
Expand All @@ -56,7 +55,6 @@ impl Data for BoxedData {
(**self).query_links(builder, query)
}
#[inline]
#[cfg(feature = "unique")]
fn get_id(&self) -> Option<ID> {
(**self).get_id()
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Show which crate feature enables conditionally compiled APIs in documentation.
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![warn(missing_debug_implementations, unreachable_pub)]
#![warn(
missing_debug_implementations,
unreachable_pub,
clippy::unwrap_used,
clippy::missing_inline_in_public_items
)]
#![allow(clippy::module_name_repetitions)]

pub mod data;
pub mod link_builder;
Expand Down
4 changes: 4 additions & 0 deletions src/link_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ impl<T> Link for T
where
T: Data + 'static,
{
#[inline]
fn key(&self) -> Option<&dyn Data> {
None
}

#[inline]
fn target(&self) -> &dyn Data {
self
}
Expand All @@ -78,10 +80,12 @@ where
K: Data + 'static,
T: Data + 'static,
{
#[inline]
fn key(&self) -> Option<&dyn Data> {
Some(&self.0)
}

#[inline]
fn target(&self) -> &dyn Data {
&self.1
}
Expand Down
4 changes: 4 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ pub struct Query {
}

impl Query {
#[inline]
#[must_use]
pub fn new(selector: LinkSelector) -> Self {
Query { selector }
}

#[inline]
#[must_use]
pub fn build(mut self) -> Self {
Selector::<BoxedData>::optimize(&mut self.selector);
self
}

#[inline]
#[must_use]
pub fn build_unoptimized(self) -> Self {
self
}

#[inline]
#[must_use]
pub fn selector(&self) -> &LinkSelector {
&self.selector
Expand Down
1 change: 1 addition & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ pub struct Value<'a> {
}

impl<'a> Value<'a> {
#[inline]
pub fn from_data<D: crate::Data + ?Sized>(data: &'a D) -> Self {
let mut value = Self::default();
data.provide_value(&mut value);
Expand Down

0 comments on commit 2321346

Please sign in to comment.