Skip to content

Commit be5bbca

Browse files
committed
Session 11: Code Quality - Unused Self Arguments - Major Progress
Fixed major unused self argument issues by properly converting methods to associated functions: - Fixed core.rs: generate_field method converted to associated function - Fixed fields.rs: get_rust_type and get_default_value methods converted to associated functions - Fixed validation.rs: generate_pattern_check and generate_range_validation methods converted to associated functions - Fixed implementations.rs: generate_class_tests method converted to associated function - Fixed all call sites in builders.rs, classes.rs, and rust_traits.rs to use Self:: syntax - Converted 6+ methods that don't use self state to associated functions Core library compiles cleanly Current clippy warnings in core lib: 774 (with 209 unused self warnings remaining)
1 parent ee49895 commit be5bbca

File tree

7 files changed

+12
-17
lines changed

7 files changed

+12
-17
lines changed

linkml-service/src/generator/builders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl RustGenerator {
3636
for slot_name in &all_slots {
3737
if let Some(slot) = schema.slots.get(slot_name) {
3838
let field_name = Self::convert_field_name(slot_name);
39-
let field_type = self.get_rust_type(slot, schema);
39+
let field_type = Self::get_rust_type(slot, schema);
4040

4141
writeln!(
4242
output,
@@ -115,7 +115,7 @@ impl RustGenerator {
115115
indent: &IndentStyle,
116116
) -> GeneratorResult<()> {
117117
let field_name = Self::convert_field_name(slot_name);
118-
let field_type = self.get_rust_type(slot, schema);
118+
let field_type = Self::get_rust_type(slot, schema);
119119

120120
// Documentation
121121
if options.include_docs {

linkml-service/src/generator/classes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl RustGenerator {
160160
for slot_name in &all_slots {
161161
if let Some(slot) = schema.slots.get(slot_name) {
162162
let field_name = Self::convert_field_name(slot_name);
163-
let default_value = self.get_default_value(slot, schema);
163+
let default_value = Self::get_default_value(slot, schema);
164164

165165
writeln!(
166166
output,

linkml-service/src/generator/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl RustGenerator {
152152
// Generate fields for each slot
153153
for slot_name in &slots {
154154
if let Some(slot_def) = schema.slots.get(slot_name) {
155-
self.generate_field(&mut output, slot_name, slot_def, schema)?;
155+
Self::generate_field(&mut output, slot_name, slot_def, schema)?;
156156
}
157157
}
158158
}
@@ -162,7 +162,7 @@ impl RustGenerator {
162162
}
163163

164164
/// Generate a field from a slot definition
165-
pub(super) fn generate_field(&self, output: &mut String, slot_name: &str, slot_def: &SlotDefinition, schema: &SchemaDefinition) -> GeneratorResult<()> {
165+
pub(super) fn generate_field(output: &mut String, slot_name: &str, slot_def: &SlotDefinition, schema: &SchemaDefinition) -> GeneratorResult<()> {
166166
// Add field documentation
167167
if let Some(ref desc) = slot_def.description {
168168
writeln!(output, " /// {desc}").map_err(Self::fmt_error_to_generator_error)?;

linkml-service/src/generator/fields.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl RustGenerator {
4848
}
4949

5050
// Field definition
51-
let field_type = self.get_rust_type(slot, schema);
51+
let field_type = Self::get_rust_type(slot, schema);
5252
writeln!(
5353
output,
5454
"{}pub {}: {},",
@@ -65,7 +65,6 @@ impl RustGenerator {
6565

6666
/// Get Rust type for a slot
6767
pub(super) fn get_rust_type(
68-
&self,
6968
slot: &SlotDefinition,
7069
schema: &SchemaDefinition,
7170
) -> String {
@@ -116,7 +115,6 @@ impl RustGenerator {
116115

117116
/// Get default value for a field
118117
pub(super) fn get_default_value(
119-
&self,
120118
slot: &SlotDefinition,
121119
schema: &SchemaDefinition,
122120
) -> String {

linkml-service/src/generator/implementations.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl RustGenerator {
146146

147147
// Generate tests for each class
148148
for (class_name, class) in &schema.classes {
149-
self.generate_class_tests(&mut output, class_name, class, schema, options)?;
149+
Self::generate_class_tests(&mut output, class_name, class, schema, options)?;
150150
}
151151

152152
writeln!(&mut output, "}}")
@@ -176,7 +176,6 @@ impl RustGenerator {
176176

177177
/// Generate tests for a specific class
178178
fn generate_class_tests(
179-
&self,
180179
output: &mut String,
181180
class_name: &str,
182181
_class: &ClassDefinition,

linkml-service/src/generator/rust_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl RustGenerator {
6969
if let Some(slot) = schema.slots.get(slot_name)
7070
&& (slot.identifier == Some(true) || slot.required == Some(true)) {
7171
let field_name = BaseCodeFormatter::to_snake_case(slot_name);
72-
let return_type = self.get_rust_type(slot, schema);
72+
let return_type = Self::get_rust_type(slot, schema);
7373
writeln!(&mut output).map_err(Self::fmt_error_to_generator_error)?;
7474
writeln!(&mut output, " /// Get the {field_name} field")
7575
.map_err(Self::fmt_error_to_generator_error)?;

linkml-service/src/generator/validation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ impl RustGenerator {
148148
field_name
149149
)
150150
.map_err(Self::fmt_error_to_generator_error)?;
151-
self.generate_pattern_check(output, slot_name, pattern, "item", indent.to_string(3))?;
151+
Self::generate_pattern_check(output, slot_name, pattern, "item", indent.to_string(3))?;
152152
writeln!(output, "{}}}", indent.to_string(2))
153153
.map_err(Self::fmt_error_to_generator_error)?;
154154
} else if slot.required.unwrap_or(false) {
155155
// Validate required field directly
156-
self.generate_pattern_check(output, slot_name, pattern, &format!("&self.{field_name}"), indent.to_string(2))?;
156+
Self::generate_pattern_check(output, slot_name, pattern, &format!("&self.{field_name}"), indent.to_string(2))?;
157157
} else {
158158
// Validate optional field if present
159159
writeln!(
@@ -163,7 +163,7 @@ impl RustGenerator {
163163
field_name
164164
)
165165
.map_err(Self::fmt_error_to_generator_error)?;
166-
self.generate_pattern_check(output, slot_name, pattern, "value", indent.to_string(3))?;
166+
Self::generate_pattern_check(output, slot_name, pattern, "value", indent.to_string(3))?;
167167
writeln!(output, "{}}}", indent.to_string(2))
168168
.map_err(Self::fmt_error_to_generator_error)?;
169169
}
@@ -173,7 +173,7 @@ impl RustGenerator {
173173
if let Some(range) = &slot.range
174174
&& matches!(range.as_str(), "integer" | "int" | "float" | "double")
175175
&& let (Some(min_val), Some(max_val)) = (&slot.minimum_value, &slot.maximum_value) {
176-
self.generate_range_validation(output, slot_name, &field_name, min_val, max_val, slot, indent)?;
176+
Self::generate_range_validation(output, slot_name, &field_name, min_val, max_val, slot, indent)?;
177177
}
178178

179179
writeln!(output).map_err(Self::fmt_error_to_generator_error)?;
@@ -182,7 +182,6 @@ impl RustGenerator {
182182

183183
/// Generate pattern validation check
184184
fn generate_pattern_check(
185-
&self,
186185
output: &mut String,
187186
slot_name: &str,
188187
pattern: &str,
@@ -222,7 +221,6 @@ impl RustGenerator {
222221
/// Generate range validation for numeric fields
223222
#[allow(clippy::too_many_arguments)]
224223
fn generate_range_validation(
225-
&self,
226224
output: &mut String,
227225
slot_name: &str,
228226
field_name: &str,

0 commit comments

Comments
 (0)