Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh committed Jan 9, 2024
1 parent 040ed4c commit 8765e2d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ flat-map-option = "deny"
semicolon-if-nothing-returned = "deny"
manual-assert = "deny"
needless-pass-by-value = "deny"
trivially-copy-pass-by-ref = "deny"

[profile.dev]
opt-level = 1
Expand Down
16 changes: 9 additions & 7 deletions dunge/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub type Update = Result<(), ForeignShader>;
pub(crate) fn update<G>(
state: &State,
uni: &mut UniqueBinding,
handler: GroupHandler<G>,
handler: &GroupHandler<G>,
group: &G,
) -> Update
where
Expand Down Expand Up @@ -183,9 +183,10 @@ impl<'a> Binder<'a> {
panic!("too many bindings");
};

if layout.tyid != TypeId::of::<G::Projection>() {
panic!("group type doesn't match");
}
assert!(
layout.tyid == TypeId::of::<G::Projection>(),
"group type doesn't match",
);

let layout = Arc::clone(&layout.bind);
let entries = visit(group);
Expand All @@ -207,9 +208,10 @@ impl<'a> Binder<'a> {
}

pub fn into_binding(self) -> UniqueBinding {
if self.groups.len() != self.layout.len() {
panic!("some group bindings is not set");
}
assert!(
self.groups.len() == self.layout.len(),
"some group bindings is not set",
);

let binding = SharedBinding::new(self.shader_id, self.groups);
UniqueBinding(binding)
Expand Down
4 changes: 2 additions & 2 deletions dunge/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ impl Context {
D: Draw,
{
let view = RenderView::from_texture(texture.draw_texture());
self.0.draw(render, view, draw)
self.0.draw(render, view, draw);
}

pub fn update_group<G>(
&self,
uni: &mut UniqueBinding,
handler: GroupHandler<G>,
handler: &GroupHandler<G>,
group: &G,
) -> Update
where
Expand Down
2 changes: 1 addition & 1 deletion dunge/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ where
D: Draw + ?Sized,
{
fn draw(&self, frame: Frame) {
(**self).draw(frame)
(**self).draw(frame);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dunge/src/el.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
return;
}

view.request_redraw()
view.request_redraw();
}
StartCause::WaitCancelled {
requested_resume, ..
Expand All @@ -111,7 +111,7 @@ where
None => ControlFlow::wait_duration(WAIT_TIME),
};

target.set_control_flow(flow)
target.set_control_flow(flow);
}
StartCause::Poll => log::debug!("poll"),
StartCause::Init => log::debug!("init"),
Expand Down
2 changes: 1 addition & 1 deletion dunge/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a> BoundTexture<'a> {
Self(texture.bind_texture())
}

pub(crate) fn get(&self) -> &'a Texture {
pub(crate) fn get(self) -> &'a Texture {
self.0
}
}
Expand Down
21 changes: 10 additions & 11 deletions dunge/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {

pub struct SetLayer<'p, V> {
shader_id: usize,
has_bindings: bool,
no_bindings: bool,
pass: RenderPass<'p>,
vert: PhantomData<V>,
}
Expand All @@ -17,9 +17,11 @@ impl<'p, V> SetLayer<'p, V> {
B: Binding,
{
let bind = bind.binding();
if self.shader_id != bind.shader_id {
panic!("the binding doesn't belong to this shader");
}

assert!(
self.shader_id == bind.shader_id,
"the binding doesn't belong to this shader",
);

for (id, group) in iter::zip(0.., bind.groups) {
self.pass.set_bind_group(id, group, &[]);
Expand All @@ -29,10 +31,7 @@ impl<'p, V> SetLayer<'p, V> {
}

pub fn bind_empty(&mut self) -> BoundLayer<'_, 'p, V> {
if self.has_bindings {
panic!("ths shader has bindings");
}

assert!(self.no_bindings, "ths shader has any bindings");
BoundLayer::new(&mut self.pass)
}
}
Expand Down Expand Up @@ -63,7 +62,7 @@ impl BoundLayer<'_, '_, ()> {

pub struct Layer<V> {
shader_id: usize,
has_bindings: bool,
no_bindings: bool,
format: Format,
render: RenderPipeline,
vertex: PhantomData<V>,
Expand Down Expand Up @@ -111,7 +110,7 @@ impl<V> Layer<V> {
let render = state.device().create_render_pipeline(&desc);
Self {
shader_id: shader.id(),
has_bindings: !shader.groups().is_empty(),
no_bindings: shader.groups().is_empty(),
format,
render,
vertex: PhantomData,
Expand All @@ -126,7 +125,7 @@ impl<V> Layer<V> {
pass.set_pipeline(&self.render);
SetLayer {
shader_id: self.shader_id,
has_bindings: self.has_bindings,
no_bindings: self.no_bindings,
pass,
vert: PhantomData,
}
Expand Down
7 changes: 4 additions & 3 deletions dunge/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ impl Frame<'_, '_> {
pub fn layer<'p, V>(&'p mut self, layer: &'p Layer<V>, opts: Options) -> SetLayer<'p, V> {
use wgpu::*;

if self.view.format != layer.format() {
panic!("layer format doesn't match frame format");
}
assert!(
self.view.format == layer.format(),
"layer format doesn't match frame format",
);

let attachment = RenderPassColorAttachment {
view: self.view.txview,
Expand Down
8 changes: 5 additions & 3 deletions dunge/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ impl CopyBuffer {

let texture = &texture.inner;
let (width, height) = self.size;
if texture.width() > width || texture.height() != height {
panic!("texture size doesn't match buffer size");
}

assert!(
texture.width() <= width && texture.height() == height,
"texture size doesn't match buffer size",
);

encoder.copy_texture_to_buffer(
ImageCopyTexture {
Expand Down

0 comments on commit 8765e2d

Please sign in to comment.