Re: [PATCH v6 3/3] rust: platform: allow ioremap of platform resources

From: Alice Ryhl
Date: Fri Jan 31 2025 - 06:36:45 EST


On Fri, Jan 31, 2025 at 11:19 AM Daniel Sedlak <daniel@xxxxxxxxxx> wrote:
>
> Hi,
>
> On 1/30/25 11:05 PM, Daniel Almeida wrote:
> > +
> > + /// Same as [`Self::ioremap_resource`] but with exclusive access to the underlying
> > + /// region.
> > + pub fn ioremap_resource_exclusive(
> > + &self,
> > + resource: &Resource,
> > + ) -> Result<Devres<ExclusiveIoMem<0>>> {
> > + self.ioremap_resource_exclusive_sized::<0>(resource)
> > + }
> > +
> > + /// Returns the resource at `index`, if any.
> > + pub fn resource(&self, index: u32) -> Option<&Resource> {
>
> Maybe we could utilize the Index [1] trait to make the API more rust~ish?
> Or at least name it `resource_by_index` to keep consistency with
> `resource_by_name`?
>
> Link: https://doc.rust-lang.org/core/ops/trait.Index.html [1]

Using the index trait would result in syntax like device[7] to get the
resource at index 7. I think that would be unclear because it's not
obvious that devices should behave like an array of resources.

Alice