Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 85 additions & 67 deletions derive/src/difference.rs

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,23 @@ impl Data {
}

impl Generic {
pub fn full(&self) -> String {
pub fn full(&self) -> &str {
match &self {
Generic::Const { name, .. } => name.clone(),
Generic::Regular { name, .. } => name.clone(),
Generic::Lifetime { name, .. } => name.clone(),
Generic::WhereBounded { name, .. } => name.clone(),
Generic::Const { name, .. } => name,
Generic::Regular { name, .. } => name,
Generic::Lifetime { name, .. } => name,
Generic::WhereBounded { name, .. } => name,
}
}

fn lifetime_prefix(&self) -> &str {
fn lifetime_prefix(&self) -> &'static str {
match &self {
Generic::Lifetime { .. } => "\'",
_ => "",
}
}

fn const_prefix(&self) -> &str {
fn const_prefix(&self) -> &'static str {
match &self {
Generic::Const { .. } => "const ",
_ => "",
Expand Down Expand Up @@ -1421,7 +1421,7 @@ fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T
// let mut generic_bounds = Vec::new();
// let mut in_type = true;
while let Some(gen) = next_generic(source) {
if already.insert(gen.full()) {
if already.insert(gen.full().to_owned()) {
ret.push(gen);
} else {
match (
Expand Down Expand Up @@ -1453,7 +1453,7 @@ fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T
panic!("mismatched generic types")
}
}
}
};
let Some(_) = next_exact_punct(source, ",") else {
break;
};
Expand All @@ -1470,7 +1470,7 @@ fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T
}

while let Some(gen) = next_generic(source) {
if already.insert(gen.full()) {
if already.insert(gen.full().to_owned()) {
let gen = match gen {
Generic::Regular { name, bounds, .. } => Generic::WhereBounded { name, bounds },
where_bounded @ Generic::WhereBounded { .. } => where_bounded,
Expand Down
10 changes: 5 additions & 5 deletions derive/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum CollectionStrategy {
}

#[cfg(feature = "generated_setters")]
pub fn attrs_setter(attributes: &[crate::parse::Attribute]) -> (bool, bool, Option<String>) {
pub fn attrs_setter(attributes: &[crate::parse::Attribute]) -> (bool, bool, Option<&str>) {
let skip = attributes
.iter()
.any(|attr| attr.tokens.len() == 1 && attr.tokens[0] == "skip_setter");
Expand All @@ -33,7 +33,7 @@ pub fn attrs_setter(attributes: &[crate::parse::Attribute]) -> (bool, bool, Opti

let Some(name_override) = attributes.iter().find_map(|attr| {
if attr.tokens.len() == 2 && attr.tokens[0] == "setter_name" {
Some(attr.tokens[1].clone())
Some(&attr.tokens[1])
} else {
None
}
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn attrs_collection_type(attributes: &[crate::parse::Attribute]) -> Option<C
pub fn attrs_map_strategy(attributes: &[crate::parse::Attribute]) -> Option<MapStrategy> {
attributes.iter().find_map(|attr| {
if attr.tokens.len() == 2 && attr.tokens[0] == "map_equality" {
let strategy = match attr.tokens[1].clone().as_str() {
let strategy = match attr.tokens[1].as_str() {
"key_only" => MapStrategy::KeyOnly,
"key_and_value" => MapStrategy::KeyAndValue,
_ => {
Expand All @@ -101,10 +101,10 @@ pub fn attrs_map_strategy(attributes: &[crate::parse::Attribute]) -> Option<MapS
})
}

pub fn attrs_expose(attributes: &[crate::parse::Attribute]) -> Option<Option<String>> {
pub fn attrs_expose(attributes: &[crate::parse::Attribute]) -> Option<Option<&str>> {
attributes.iter().find_map(|attr| match attr.tokens.len() {
1 if attr.tokens[0].starts_with("expose") => Some(None),
2.. if attr.tokens[0] == "expose" => Some(Some(attr.tokens[1].to_string())),
2.. if attr.tokens[0] == "expose" => Some(Some(attr.tokens[1].as_str())),
_ => None,
})
}
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fmt:
cargo fmt && cargo fmt --manifest-path ./derive/Cargo.toml
clippy:
cargo clippy --all-features && cargo clippy --all-features --manifest-path ./derive/Cargo.toml
test:
cargo test && cargo test --all-features
1 change: 1 addition & 0 deletions src/collections/ordered_array_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ fn create_full_change_table<T: PartialEq>(
entry[0] = ChangeInternal::Insert(i * INSERT_COST);
}

#[allow(clippy::needless_range_loop)]
for j in 0..=source.len() {
table[0][j] = ChangeInternal::Delete(j * DELETE_COST)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct TestDeriveAll<
[i32; N]: Default,
[B; N]: Default,
dyn Fn(&B): PartialEq + Clone + core::fmt::Debug,
(dyn core::fmt::Debug + Send + 'static): Debug,
dyn core::fmt::Debug + Send + 'static: Debug,
{
f1: (),
f2: [A; N],
Expand Down
4 changes: 3 additions & 1 deletion tests/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use std::{
fmt::Debug,
num::Wrapping,
};
use structdiff::{Difference, StructDiff};
use structdiff::Difference;

#[allow(dead_code)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Clone, Difference, Default)]
#[difference(setters)]
Expand All @@ -19,6 +20,7 @@ pub struct Test {
pub test5: Option<usize>,
}

#[allow(dead_code)]
#[derive(Debug, PartialEq, Clone, Difference)]
#[difference(setters)]
pub struct TestSkip<A>
Expand Down
2 changes: 2 additions & 0 deletions tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use nanorand::{Rng, WyRand};
use nanoserde::{DeBin, SerBin};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg_attr(not(feature = "generated_setters"), expect(unused_imports))]
use structdiff::{Difference, StructDiff};

pub trait RandValue
Expand Down Expand Up @@ -96,6 +97,7 @@ impl RandValue for TestEnum {

#[derive(Difference, Default, PartialEq, Debug, Clone)]
#[difference(setters)]
#[allow(unused)]
pub struct TestSetters {
#[difference(setter_name = "testing123", recurse)]
pub f0: Test,
Expand Down
Loading