Re: [PATCH 2/4] rust: scatterlist: Add type-state abstraction for sg_table

From: Danilo Krummrich
Date: Mon Aug 18 2025 - 08:30:02 EST


On Mon Aug 18, 2025 at 1:16 PM CEST, Danilo Krummrich wrote:
> On Mon Aug 18, 2025 at 11:52 AM CEST, Alice Ryhl wrote:
>> On Fri, Aug 15, 2025 at 07:10:03PM +0200, Danilo Krummrich wrote:
>>> +impl<P> Owned<P>
>>> +where
>>> + for<'a> P: page::AsPageIter<Iter<'a> = VmallocPageIter<'a>> + 'static,
>>
>> If you specifically require the iterator type to be VmallocPageIter,
>> then I would hard-code that in the trait instead of specifying it here.
>
> I do not follow, hard-code in which trait?
>
>> But I think you just want `P: AsPageIter`.
>
> Yeah, I thought for now it's probably good enough to require VmallocPageIter and
> revisit once we get more implementors of AsPageIter, but I think we can also do
> it right away.
>
> I think we'd need a trait PageIterator, which implements page_count(), since we
> technically can't rely on Iterator::size_hint(). Though, in this case I think we
> can also just make AsPageIter::Iter: ExactSizeIterator?

Forgot to mention this [1] as for why we expect VmallocPageIter (at least for
now).

[1] https://lore.kernel.org/rust-for-linux/958ef505-8713-4f88-9f24-5971ce8a08ce@xxxxxxxxxx/