Skip to content

Commit

Permalink
reflect: implement exactsizeiter for iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Sep 4, 2024
1 parent bbcaf59 commit cc29bef
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spirv-cross2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spirv-cross2"
version = "0.3.3"
version = "0.3.5"
edition = "2021"

license = "MIT OR Apache-2.0"
Expand Down
6 changes: 6 additions & 0 deletions spirv-cross2/src/compile/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ pub struct GlslExtensionsIter<'a>(
PhantomCompiler<'a>,
);

impl ExactSizeIterator for GlslExtensionsIter<'_> {
fn len(&self) -> usize {
self.0.len()
}
}

impl<'comp> Iterator for GlslExtensionsIter<'comp> {
type Item = ContextStr<'comp>;

Expand Down
6 changes: 6 additions & 0 deletions spirv-cross2/src/reflect/combined_image_samplers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct CombinedImageSamplerIter<'a>(
slice::Iter<'a, sys::spvc_combined_image_sampler>,
);

impl ExactSizeIterator for CombinedImageSamplerIter<'_> {
fn len(&self) -> usize {
self.1.len()
}
}

impl Iterator for CombinedImageSamplerIter<'_> {
type Item = CombinedImageSampler;

Expand Down
6 changes: 6 additions & 0 deletions spirv-cross2/src/reflect/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ pub struct SpecializationConstantIter<'a>(
slice::Iter<'a, spvc_specialization_constant>,
);

impl ExactSizeIterator for SpecializationConstantIter<'_> {
fn len(&self) -> usize {
self.1.len()
}
}

impl Iterator for SpecializationConstantIter<'_> {
type Item = SpecializationConstant;

Expand Down
14 changes: 13 additions & 1 deletion spirv-cross2/src/reflect/entry_points.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::{SpirvCrossError, ToContextError};
use crate::handle::Handle;
use crate::reflect::try_valid_slice;
use crate::reflect::{try_valid_slice, CombinedImageSamplerIter};
use crate::string::ContextStr;
use crate::{error, spirv};
use crate::{Compiler, ContextRoot};
Expand All @@ -24,6 +24,12 @@ impl<'a> Iterator for ExtensionsIter<'a> {
}
}

impl ExactSizeIterator for ExtensionsIter<'_> {
fn len(&self) -> usize {
self.0.len()
}
}

/// Querying declared properties of the SPIR-V module.
impl<'ctx, T> Compiler<'ctx, T> {
/// Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.
Expand Down Expand Up @@ -131,6 +137,12 @@ pub struct EntryPoint<'a> {
pub name: ContextStr<'a>,
}

impl ExactSizeIterator for EntryPointIter<'_> {
fn len(&self) -> usize {
self.0.len()
}
}

impl<'a> Iterator for EntryPointIter<'a> {
type Item = EntryPoint<'a>;

Expand Down
12 changes: 12 additions & 0 deletions spirv-cross2/src/reflect/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ pub struct ResourceIter<'a>(
slice::Iter<'a, spvc_reflected_resource>,
);

impl ExactSizeIterator for ResourceIter<'_> {
fn len(&self) -> usize {
self.1.len()
}
}

impl<'a> Iterator for ResourceIter<'a> {
type Item = Resource<'a>;

Expand Down Expand Up @@ -329,6 +335,12 @@ impl Clone for BuiltinResource<'_> {
}
}

impl ExactSizeIterator for BuiltinResourceIter<'_> {
fn len(&self) -> usize {
self.1.len()
}
}

/// All SPIR-V resources declared in the module.
#[derive(Debug)]
pub struct AllResources<'a> {
Expand Down

0 comments on commit cc29bef

Please sign in to comment.