Skip to content

Commit 5f4f366

Browse files
konardclaude
andcommitted
Fix Clippy warnings and add lint allows
- Add crate-level allows for pedantic clippy lints - Fix doc comments with backticks around type names - Add #[must_use] attributes where appropriate - Convert methods with unused self to associated functions - Fix redundant closures with method references - Fix format string arguments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 24e4d3b commit 5f4f366

File tree

8 files changed

+70
-62
lines changed

8 files changed

+70
-62
lines changed

rust/examples/basic_usage.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Basic usage example for the Links Client library
22
3+
#![allow(clippy::uninlined_format_args)]
4+
35
use links_client::services::link_db_service::Link;
46
use links_client::{ILinks, LinkConstants};
57

rust/src/api/ilinks.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//! ILinks - Universal flat API compatible with Platform.Data ILinks interface
1+
//! `ILinks` - Universal flat API compatible with Platform.Data `ILinks` interface
22
33
use std::path::PathBuf;
44
use thiserror::Error;
55
use tracing::debug;
66

77
use crate::services::link_db_service::{Link, LinkDBError, LinkDBService};
88

9-
/// Errors that can occur when using ILinks
9+
/// Errors that can occur when using `ILinks`
1010
#[derive(Error, Debug)]
1111
pub enum ILinksError {
1212
#[error("LinkDB error: {0}")]
@@ -22,7 +22,7 @@ pub enum ILinksError {
2222
NoLinksFound,
2323
}
2424

25-
/// Constants for ILinks operations
25+
/// Constants for `ILinks` operations
2626
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2727
pub enum LinkConstants {
2828
/// Continue iteration
@@ -35,6 +35,7 @@ pub enum LinkConstants {
3535

3636
impl LinkConstants {
3737
/// Get the numeric value for Any constant
38+
#[must_use]
3839
pub const fn any_value() -> u64 {
3940
0
4041
}
@@ -49,7 +50,7 @@ pub struct LinkChange {
4950
pub after: Option<Link>,
5051
}
5152

52-
/// ILinks - Universal flat Turing complete API for Links
53+
/// `ILinks` - Universal flat Turing complete API for Links
5354
/// Compatible with <https://github.com/linksplatform/Data/blob/main/csharp/Platform.Data/ILinks.cs>
5455
///
5556
/// Flat meaning it only works with a single link at a time.
@@ -58,7 +59,7 @@ pub struct ILinks {
5859
}
5960

6061
impl ILinks {
61-
/// Create a new ILinks instance
62+
/// Create a new `ILinks` instance
6263
///
6364
/// # Arguments
6465
///
@@ -70,6 +71,7 @@ impl ILinks {
7071
}
7172

7273
/// Get constants for this Links instance
74+
#[must_use]
7375
pub const fn get_constants(&self) -> LinkConstants {
7476
LinkConstants::Any
7577
}
@@ -85,11 +87,11 @@ impl ILinks {
8587
pub async fn count(&self, restriction: Option<&[u64]>) -> Result<usize, ILinksError> {
8688
let all_links = self.db.read_all_links().await?;
8789

88-
if restriction.is_none() || restriction.map_or(true, |r| r.is_empty()) {
90+
if restriction.is_none() || restriction.map_or(true, <[u64]>::is_empty) {
8991
return Ok(all_links.len());
9092
}
9193

92-
let filtered = self.filter_links(&all_links, restriction);
94+
let filtered = Self::filter_links(&all_links, restriction);
9395
Ok(filtered.len())
9496
}
9597

@@ -108,7 +110,7 @@ impl ILinks {
108110
F: FnMut(&Link) -> LinkConstants,
109111
{
110112
let all_links = self.db.read_all_links().await?;
111-
let filtered = self.filter_links(&all_links, restriction);
113+
let filtered = Self::filter_links(&all_links, restriction);
112114

113115
if let Some(ref mut h) = handler {
114116
for link in filtered {
@@ -173,7 +175,7 @@ impl ILinks {
173175
where
174176
F: FnMut(LinkChange),
175177
{
176-
if restriction.is_none() || restriction.map_or(true, |r| r.is_empty()) {
178+
if restriction.is_none() || restriction.map_or(true, <[u64]>::is_empty) {
177179
return Err(ILinksError::InvalidRestriction(
178180
"Restriction required for update".to_string(),
179181
));
@@ -186,7 +188,7 @@ impl ILinks {
186188
}
187189

188190
let all_links = self.db.read_all_links().await?;
189-
let filtered = self.filter_links(&all_links, restriction);
191+
let filtered = Self::filter_links(&all_links, restriction);
190192

191193
if filtered.is_empty() {
192194
return Err(ILinksError::NoLinksFound);
@@ -230,14 +232,14 @@ impl ILinks {
230232
where
231233
F: FnMut(LinkChange),
232234
{
233-
if restriction.is_none() || restriction.map_or(true, |r| r.is_empty()) {
235+
if restriction.is_none() || restriction.map_or(true, <[u64]>::is_empty) {
234236
return Err(ILinksError::InvalidRestriction(
235237
"Restriction required for delete".to_string(),
236238
));
237239
}
238240

239241
let all_links = self.db.read_all_links().await?;
240-
let filtered = self.filter_links(&all_links, restriction);
242+
let filtered = Self::filter_links(&all_links, restriction);
241243

242244
if filtered.is_empty() {
243245
return Err(ILinksError::NoLinksFound);
@@ -260,7 +262,7 @@ impl ILinks {
260262
}
261263

262264
/// Helper method to filter links based on restriction
263-
fn filter_links(&self, links: &[Link], restriction: Option<&[u64]>) -> Vec<Link> {
265+
fn filter_links(links: &[Link], restriction: Option<&[u64]>) -> Vec<Link> {
264266
let restriction = match restriction {
265267
Some(r) if !r.is_empty() => r,
266268
_ => return links.to_vec(),
@@ -305,7 +307,6 @@ mod tests {
305307

306308
#[test]
307309
fn test_filter_links() {
308-
let links = ILinks::new(None).unwrap();
309310
let all_links = vec![
310311
Link {
311312
id: 1,
@@ -325,21 +326,21 @@ mod tests {
325326
];
326327

327328
// Filter by ID
328-
let filtered = links.filter_links(&all_links, Some(&[1]));
329+
let filtered = ILinks::filter_links(&all_links, Some(&[1]));
329330
assert_eq!(filtered.len(), 1);
330331
assert_eq!(filtered[0].id, 1);
331332

332333
// Filter by source and target
333-
let filtered = links.filter_links(&all_links, Some(&[2, 3]));
334+
let filtered = ILinks::filter_links(&all_links, Some(&[2, 3]));
334335
assert_eq!(filtered.len(), 1);
335336
assert_eq!(filtered[0].id, 1);
336337

337338
// Filter with Any source
338-
let filtered = links.filter_links(&all_links, Some(&[0, 3]));
339+
let filtered = ILinks::filter_links(&all_links, Some(&[0, 3]));
339340
assert_eq!(filtered.len(), 1);
340341

341342
// No restriction returns all
342-
let filtered = links.filter_links(&all_links, None);
343+
let filtered = ILinks::filter_links(&all_links, None);
343344
assert_eq!(filtered.len(), 3);
344345
}
345346
}

rust/src/api/recursive_links.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! RecursiveLinks - Recursive API for working with hierarchical link structures
1+
//! `RecursiveLinks` - Recursive API for working with hierarchical link structures
22
33
use std::future::Future;
44
use std::path::PathBuf;
@@ -8,7 +8,7 @@ use tracing::debug;
88

99
use crate::services::link_db_service::{Link, LinkDBError, LinkDBService};
1010

11-
/// Errors that can occur when using RecursiveLinks
11+
/// Errors that can occur when using `RecursiveLinks`
1212
#[derive(Error, Debug)]
1313
pub enum RecursiveLinksError {
1414
#[error("LinkDB error: {0}")]
@@ -30,7 +30,7 @@ pub struct LinkNode {
3030
pub children: Vec<LinkNode>,
3131
}
3232

33-
/// RecursiveLinks - API for working with hierarchical link structures
33+
/// `RecursiveLinks` - API for working with hierarchical link structures
3434
///
3535
/// This API provides methods for traversing and manipulating link trees,
3636
/// where links can form parent-child relationships.
@@ -41,11 +41,12 @@ pub struct RecursiveLinks {
4141
}
4242

4343
impl RecursiveLinks {
44-
/// Create a new RecursiveLinks instance
44+
/// Create a new `RecursiveLinks` instance
4545
///
4646
/// # Arguments
4747
///
4848
/// * `db_path` - Optional path to the database file
49+
#[must_use]
4950
pub fn new(db_path: Option<PathBuf>) -> Self {
5051
Self {
5152
db: LinkDBService::new(db_path),
@@ -98,7 +99,7 @@ impl RecursiveLinks {
9899
}
99100
}
100101

101-
/// Recursively build a tree node (using Box::pin for async recursion)
102+
/// Recursively build a tree node (using `Box::pin` for async recursion)
102103
fn build_tree_impl<'a>(
103104
&'a self,
104105
link: Link,
@@ -140,7 +141,7 @@ impl RecursiveLinks {
140141
Ok(true)
141142
}
142143

143-
/// Recursively delete a link and its children (using Box::pin for async recursion)
144+
/// Recursively delete a link and its children (using `Box::pin` for async recursion)
144145
fn delete_link_impl<'a>(
145146
&'a self,
146147
id: u64,
@@ -160,26 +161,25 @@ impl RecursiveLinks {
160161
/// Count all links in a tree starting from the given root
161162
pub async fn count_tree(&self, root_id: u64) -> Result<usize, RecursiveLinksError> {
162163
let tree = self.build_tree(root_id).await?;
163-
match tree {
164-
Some(node) => Ok(self.count_nodes(&node)),
165-
None => Ok(0),
166-
}
164+
Ok(tree.map_or(0, |node| Self::count_nodes(&node)))
167165
}
168166

169167
/// Recursively count nodes in a tree
170-
pub fn count_nodes(&self, node: &LinkNode) -> usize {
168+
#[must_use]
169+
pub fn count_nodes(node: &LinkNode) -> usize {
171170
let mut count = 1; // Count this node
172171
for child in &node.children {
173-
count += self.count_nodes(child);
172+
count += Self::count_nodes(child);
174173
}
175174
count
176175
}
177176

178177
/// Flatten a tree into a list of links (depth-first order)
179-
pub fn flatten_tree(&self, node: &LinkNode) -> Vec<Link> {
178+
#[must_use]
179+
pub fn flatten_tree(node: &LinkNode) -> Vec<Link> {
180180
let mut result = vec![node.link.clone()];
181181
for child in &node.children {
182-
result.extend(self.flatten_tree(child));
182+
result.extend(Self::flatten_tree(child));
183183
}
184184
result
185185
}
@@ -204,8 +204,6 @@ mod tests {
204204

205205
#[test]
206206
fn test_count_nodes() {
207-
let links = RecursiveLinks::new(None);
208-
209207
let tree = LinkNode {
210208
link: Link {
211209
id: 1,
@@ -239,13 +237,11 @@ mod tests {
239237
],
240238
};
241239

242-
assert_eq!(links.count_nodes(&tree), 4);
240+
assert_eq!(RecursiveLinks::count_nodes(&tree), 4);
243241
}
244242

245243
#[test]
246244
fn test_flatten_tree() {
247-
let links = RecursiveLinks::new(None);
248-
249245
let tree = LinkNode {
250246
link: Link {
251247
id: 1,
@@ -262,7 +258,7 @@ mod tests {
262258
}],
263259
};
264260

265-
let flattened = links.flatten_tree(&tree);
261+
let flattened = RecursiveLinks::flatten_tree(&tree);
266262
assert_eq!(flattened.len(), 2);
267263
assert_eq!(flattened[0].id, 1);
268264
assert_eq!(flattened[1].id, 2);

rust/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
//! }
2626
//! ```
2727
28+
// Allow some pedantic clippy lints that are too strict for this crate
29+
#![allow(clippy::fn_params_excessive_bools)]
30+
#![allow(clippy::must_use_candidate)]
31+
#![allow(clippy::use_self)]
32+
#![allow(clippy::doc_markdown)]
33+
#![allow(clippy::missing_errors_doc)]
34+
#![allow(clippy::missing_panics_doc)]
35+
#![allow(clippy::module_name_repetitions)]
36+
#![allow(clippy::uninlined_format_args)]
37+
2838
pub mod api;
2939
pub mod services;
3040
pub mod utils;

rust/src/services/auth_storage_service.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! AuthStorageService - Service for user authentication data storage
1+
//! `AuthStorageService` - Service for user authentication data storage
22
33
use std::collections::HashMap;
44
use std::path::PathBuf;
@@ -7,7 +7,7 @@ use tracing::{debug, error};
77

88
use super::link_db_service::{LinkDBError, LinkDBService};
99

10-
/// Errors that can occur when using AuthStorageService
10+
/// Errors that can occur when using `AuthStorageService`
1111
#[derive(Error, Debug)]
1212
pub enum AuthStorageError {
1313
#[error("LinkDB error: {0}")]
@@ -31,18 +31,18 @@ pub struct User {
3131
pub data: HashMap<String, String>,
3232
}
3333

34-
/// AuthStorageService - Service for user authentication data storage
34+
/// `AuthStorageService` - Service for user authentication data storage
3535
///
3636
/// This service provides methods for storing and retrieving user authentication data
37-
/// using the LinkDB backend.
37+
/// using the `LinkDB` backend.
3838
pub struct AuthStorageService {
3939
db: LinkDBService,
4040
/// Type identifier for user links
4141
user_type_id: u64,
4242
}
4343

4444
impl AuthStorageService {
45-
/// Create a new AuthStorageService with the specified database path
45+
/// Create a new `AuthStorageService` with the specified database path
4646
///
4747
/// # Arguments
4848
///

0 commit comments

Comments
 (0)