Skip to content

Commit d0abc73

Browse files
authored
chore(lambda-rs): Fix all clippy warnings
2 parents 04e1458 + 8a6dcae commit d0abc73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+468
-398
lines changed

crates/lambda-rs-args/src/lib.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(clippy::needless_return)]
2+
#![allow(clippy::items_after_test_module)]
23
//! # Lambda Args
34
//! Lambda Args is a simple argument parser for Rust. It is designed to be
45
//! simple to use and primarily for use in lambda command line applications.
@@ -72,42 +73,42 @@ pub enum ArgumentValue {
7273
String(String),
7374
}
7475

75-
impl Into<String> for ArgumentValue {
76-
fn into(self) -> String {
77-
return match self {
76+
impl From<ArgumentValue> for String {
77+
fn from(value: ArgumentValue) -> Self {
78+
return match value {
7879
ArgumentValue::String(val) => val,
79-
_ => panic!("Cannot convert {:?} into a String.", self),
80+
other => panic!("Cannot convert {:?} into a String.", other),
8081
};
8182
}
8283
}
8384

84-
impl Into<i64> for ArgumentValue {
85-
fn into(self) -> i64 {
86-
return match self {
85+
impl From<ArgumentValue> for i64 {
86+
fn from(value: ArgumentValue) -> Self {
87+
return match value {
8788
ArgumentValue::Integer(val) => val,
8889
ArgumentValue::Float(val) => val as i64,
8990
ArgumentValue::Double(val) => val as i64,
90-
_ => panic!("Cannot convert {:?} into an i64", self),
91+
other => panic!("Cannot convert {:?} into an i64", other),
9192
};
9293
}
9394
}
9495

95-
impl Into<f32> for ArgumentValue {
96-
fn into(self) -> f32 {
97-
return match self {
96+
impl From<ArgumentValue> for f32 {
97+
fn from(value: ArgumentValue) -> Self {
98+
return match value {
9899
ArgumentValue::Float(val) => val,
99-
_ => panic!("Cannot convert {:?} into a f32", self),
100+
other => panic!("Cannot convert {:?} into a f32", other),
100101
};
101102
}
102103
}
103104

104-
impl Into<f64> for ArgumentValue {
105-
fn into(self) -> f64 {
106-
return match self {
105+
impl From<ArgumentValue> for f64 {
106+
fn from(value: ArgumentValue) -> Self {
107+
return match value {
107108
ArgumentValue::Double(val) => val,
108109
ArgumentValue::Float(val) => val as f64,
109110
ArgumentValue::Integer(val) => val as f64,
110-
_ => panic!("Cannot convert {:?} into a f64", self),
111+
other => panic!("Cannot convert {:?} into a f64", other),
111112
};
112113
}
113114
}
@@ -194,7 +195,7 @@ impl Argument {
194195
}
195196

196197
pub fn arg_type(&self) -> ArgumentType {
197-
return self.arg_type.clone();
198+
return self.arg_type;
198199
}
199200

200201
/// Canonical name used for matching and display (e.g., `--output`).
@@ -406,11 +407,12 @@ impl ArgumentParser {
406407
format!(" (aliases: {})", arg.aliases().join(", "))
407408
};
408409
out.push_str(&format!(
409-
" {}{}\n {}{}{}\n",
410+
" {}{}\n {}{}{}{}\n",
410411
arg.name(),
411412
sep,
412413
desc,
413-
format!("{}{}", req, def),
414+
req,
415+
def,
414416
aliases
415417
));
416418
}
@@ -583,13 +585,13 @@ impl ArgumentParser {
583585
if matches!(pre.0.arg_type(), ArgumentType::Count) {
584586
let index = pre.2;
585587
let current = match &parsed_arguments[index].value {
586-
ArgumentValue::Integer(v) => *v as i64,
588+
ArgumentValue::Integer(v) => *v,
587589
_ => 0,
588590
};
589591
let found = self.args.get_mut(&canon).unwrap();
590592
parsed_arguments[index] = ParsedArgument::new(
591593
found.0.name.as_str(),
592-
ArgumentValue::Integer((current + 1) as i64),
594+
ArgumentValue::Integer(current + 1),
593595
);
594596
found.1 = true;
595597
} else if matches!(pre.0.arg_type(), ArgumentType::Boolean) {
@@ -619,7 +621,7 @@ impl ArgumentParser {
619621
return Err(ArgsError::UnknownArgument(msg));
620622
};
621623
let pre = self.args.get(&canon_name).unwrap();
622-
if pre.1 == true {
624+
if pre.1 {
623625
return Err(ArgsError::DuplicateArgument(pre.0.name.clone()));
624626
}
625627
// Boolean flags can be set by presence alone
@@ -636,12 +638,12 @@ impl ArgumentParser {
636638
let index = pre.2;
637639
let found = self.args.get_mut(&canon_name).unwrap();
638640
let current = match &parsed_arguments[index].value {
639-
ArgumentValue::Integer(v) => *v as i64,
641+
ArgumentValue::Integer(v) => *v,
640642
_ => 0,
641643
};
642644
parsed_arguments[index] = ParsedArgument::new(
643645
found.0.name.as_str(),
644-
ArgumentValue::Integer((current + 1) as i64),
646+
ArgumentValue::Integer(current + 1),
645647
);
646648
found.1 = true;
647649
continue;
@@ -1022,12 +1024,12 @@ mod tests {
10221024
Argument::new("--verbose").with_type(ArgumentType::Boolean),
10231025
);
10241026
let p = parser.parse(&argv(&["--verbose"])).unwrap();
1025-
assert_eq!(p.get_bool("--verbose").unwrap(), true);
1027+
assert!(p.get_bool("--verbose").unwrap());
10261028
let parser2 = ArgumentParser::new("app").with_argument(
10271029
Argument::new("--verbose").with_type(ArgumentType::Boolean),
10281030
);
10291031
let p2 = parser2.parse(&argv(&["--no-verbose"])).unwrap();
1030-
assert_eq!(p2.get_bool("--verbose").unwrap(), false);
1032+
assert!(!p2.get_bool("--verbose").unwrap());
10311033
}
10321034

10331035
#[test]
@@ -1279,12 +1281,12 @@ impl ArgumentParser {
12791281

12801282
fn assign_next_positional(
12811283
&mut self,
1282-
out: &mut Vec<ParsedArgument>,
1284+
out: &mut [ParsedArgument],
12831285
value: &str,
12841286
) -> Result<(), ArgsError> {
12851287
for pname in self.positionals.clone() {
12861288
if let Some(entry) = self.args.get_mut(&pname) {
1287-
if entry.1 == false {
1289+
if !entry.1 {
12881290
let parsed = parse_value(&entry.0, value)?;
12891291
let idx = entry.2;
12901292
out[idx] = ParsedArgument::new(entry.0.name.as_str(), parsed);
@@ -1300,7 +1302,7 @@ impl ArgumentParser {
13001302
})
13011303
}
13021304

1303-
fn get_present(&self, out: &Vec<ParsedArgument>, name: &str) -> bool {
1305+
fn get_present(&self, out: &[ParsedArgument], name: &str) -> bool {
13041306
let canon = if self.args.contains_key(name) {
13051307
name.to_string()
13061308
} else if let Some(n) = self.aliases.get(name) {

crates/lambda-rs-platform/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,3 @@ wgpu-with-vulkan = ["wgpu"]
5454
wgpu-with-metal = ["wgpu", "wgpu/metal"]
5555
wgpu-with-dx12 = ["wgpu", "wgpu/dx12"]
5656
wgpu-with-gl = ["wgpu", "wgpu/webgl"]
57-
58-
[profile.dev]
59-
crate-type = ["cdylib", "rlib"]
60-
incremental = true

crates/lambda-rs-platform/src/shader/naga.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ impl ShaderCompilerBuilder {
2929
}
3030
}
3131

32+
impl Default for ShaderCompilerBuilder {
33+
fn default() -> Self {
34+
return Self::new();
35+
}
36+
}
37+
3238
/// A shader compiler that uses naga to translate shader sources into SPIR-V.
3339
pub struct ShaderCompiler {}
3440

@@ -90,9 +96,11 @@ impl ShaderCompiler {
9096
.validate(&module)
9197
.expect("Failed to validate shader module.");
9298

93-
let mut options = spv::Options::default();
94-
options.lang_version = (1, 5);
95-
options.flags = spv::WriterFlags::empty();
99+
let options = spv::Options {
100+
lang_version: (1, 5),
101+
flags: spv::WriterFlags::empty(),
102+
..Default::default()
103+
};
96104

97105
let pipeline_options = spv::PipelineOptions {
98106
shader_stage: stage,

crates/lambda-rs-platform/src/wgpu/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111
multisampled,
112112
} => {
113113
assert_eq!(view_dimension, wgpu::TextureViewDimension::D2);
114-
assert_eq!(multisampled, false);
114+
assert!(!multisampled);
115115
match sample_type {
116116
wgpu::TextureSampleType::Float { filterable } => assert!(filterable),
117117
_ => panic!("expected float sample type"),

crates/lambda-rs-platform/src/wgpu/gpu.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl GpuBuilder {
124124
///
125125
/// Returns an error if no adapter is available, required features are
126126
/// missing, or device creation fails.
127-
pub fn build<'surface, 'window>(
127+
pub fn build<'surface>(
128128
self,
129129
instance: &Instance,
130130
surface: Option<&Surface<'surface>>,
@@ -160,12 +160,17 @@ impl GpuBuilder {
160160
adapter,
161161
device,
162162
queue,
163-
features: descriptor.required_features,
164163
limits: descriptor.required_limits,
165164
});
166165
}
167166
}
168167

168+
impl Default for GpuBuilder {
169+
fn default() -> Self {
170+
return Self::new();
171+
}
172+
}
173+
169174
/// Errors emitted while building a `Gpu`.
170175
#[derive(Debug)]
171176
pub enum GpuBuildError {
@@ -187,13 +192,12 @@ impl From<wgpu::RequestDeviceError> for GpuBuildError {
187192
}
188193

189194
/// Holds the chosen adapter along with its logical device and submission queue
190-
/// plus immutable copies of features and limits used to create the device.
195+
/// plus an immutable copy of the limits used to create the device.
191196
#[derive(Debug)]
192197
pub struct Gpu {
193198
adapter: wgpu::Adapter,
194199
device: wgpu::Device,
195200
queue: wgpu::Queue,
196-
features: wgpu::Features,
197201
limits: wgpu::Limits,
198202
}
199203

@@ -237,11 +241,6 @@ impl Gpu {
237241
&self.queue
238242
}
239243

240-
/// Features that were required and enabled during device creation.
241-
pub(crate) fn features(&self) -> wgpu::Features {
242-
self.features
243-
}
244-
245244
/// Limits captured at device creation time.
246245
pub fn limits(&self) -> GpuLimits {
247246
return GpuLimits {
@@ -307,7 +306,6 @@ mod tests {
307306
use super::*;
308307
use crate::wgpu::{
309308
instance,
310-
surface,
311309
texture,
312310
};
313311

crates/lambda-rs-platform/src/wgpu/instance.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ impl InstanceBuilder {
176176
}
177177
}
178178

179+
impl Default for InstanceBuilder {
180+
fn default() -> Self {
181+
return Self::new();
182+
}
183+
}
184+
179185
#[derive(Debug)]
180186
/// Thin wrapper over `wgpu::Instance` that preserves a user label and exposes
181187
/// a blocking `request_adapter` convenience.

crates/lambda-rs-platform/src/wgpu/pipeline.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ impl ShaderModule {
206206
pub fn raw(&self) -> &wgpu::ShaderModule {
207207
&self.raw
208208
}
209+
210+
/// Optional debug label used during creation.
211+
pub fn label(&self) -> Option<&str> {
212+
return self.label.as_deref();
213+
}
209214
}
210215

211216
/// Wrapper around `wgpu::PipelineLayout`.
@@ -220,6 +225,11 @@ impl PipelineLayout {
220225
pub fn raw(&self) -> &wgpu::PipelineLayout {
221226
return &self.raw;
222227
}
228+
229+
/// Optional debug label used during creation.
230+
pub fn label(&self) -> Option<&str> {
231+
return self.label.as_deref();
232+
}
223233
}
224234

225235
/// Builder for creating a `PipelineLayout`.
@@ -229,6 +239,12 @@ pub struct PipelineLayoutBuilder<'a> {
229239
immediate_data_ranges: Vec<ImmediateDataRange>,
230240
}
231241

242+
impl<'a> Default for PipelineLayoutBuilder<'a> {
243+
fn default() -> Self {
244+
return Self::new();
245+
}
246+
}
247+
232248
/// Align a `u32` value up to the provided power-of-two alignment.
233249
fn align_up_u32(value: u32, alignment: u32) -> u32 {
234250
if alignment == 0 {
@@ -459,10 +475,6 @@ impl RenderPipeline {
459475
pub(crate) fn raw(&self) -> &wgpu::RenderPipeline {
460476
return &self.raw;
461477
}
462-
/// Consume and return the raw pipeline.
463-
pub(crate) fn into_raw(self) -> wgpu::RenderPipeline {
464-
return self.raw;
465-
}
466478
/// Pipeline label if provided.
467479
pub fn label(&self) -> Option<&str> {
468480
return self.label.as_deref();
@@ -480,6 +492,12 @@ pub struct RenderPipelineBuilder<'a> {
480492
sample_count: u32,
481493
}
482494

495+
impl<'a> Default for RenderPipelineBuilder<'a> {
496+
fn default() -> Self {
497+
return Self::new();
498+
}
499+
}
500+
483501
impl<'a> RenderPipelineBuilder<'a> {
484502
/// New builder with defaults.
485503
pub fn new() -> Self {

crates/lambda-rs-platform/src/wgpu/render_pass.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ pub struct RenderPass<'a> {
115115
pub(super) raw: wgpu::RenderPass<'a>,
116116
}
117117

118-
#[derive(Debug)]
119-
struct RenderPassKeepAlive<'a> {
120-
color_attachments: [Option<wgpu::RenderPassColorAttachment<'a>>; 1],
121-
label: Option<String>,
122-
}
123-
124118
impl<'a> RenderPass<'a> {
125119
/// Set the active render pipeline.
126120
pub fn set_pipeline(&mut self, pipeline: &pipeline::RenderPipeline) {
@@ -254,10 +248,8 @@ impl<'a> RenderColorAttachments<'a> {
254248
&mut self,
255249
operations: wgpu::Operations<wgpu::Color>,
256250
) {
257-
for attachment in &mut self.attachments {
258-
if let Some(ref mut a) = attachment {
259-
a.ops = operations;
260-
}
251+
for a in self.attachments.iter_mut().flatten() {
252+
a.ops = operations;
261253
}
262254
}
263255

0 commit comments

Comments
 (0)