Re: [PATCH v3 1/2] rust: sizes: add DeviceSize trait for device address space constants

From: Gary Guo

Date: Fri Apr 03 2026 - 09:01:41 EST


On Fri Apr 3, 2026 at 9:21 AM BST, Alexandre Courbot wrote:
> On Fri Apr 3, 2026 at 10:36 AM JST, John Hubbard wrote:
>> On 4/1/26 6:42 PM, Alexandre Courbot wrote:
>>> On Thu Apr 2, 2026 at 6:20 AM JST, Danilo Krummrich wrote:
>>>> On Wed Apr 1, 2026 at 10:22 PM CEST, John Hubbard wrote:
>>>>> On 4/1/26 2:46 AM, Alice Ryhl wrote:
>> ...
>>>> The reason is that when I proposed this I was thinking of it as a marker trait
>>>> for "complex" types around u32, u64, etc. that we can use in DRM APIs (or any
>>>> other device centric API) though generics.
>>>>
>>>> For instance, instead of GpuVm<T>::vm_start() -> u64, it could be
>>>> GpuVm<T, V: DeviceSize>::vm_start() -> V.
>>>
>>> With the proposed naming this becomes `GpuVm<T, V: SizeConstants>`. Why
>>> not just name it `Size`? Sure it's a very common word, but we have the
>>> module to scope the name properly.
>>
>> I was waiting to see if anyone else weighed in.
>>
>> SizeConstants accurately describes what this trait provides. Size is
>> too general. Again, I think it's best to name things for what they
>> are or what they provide. And then, if they look odd in some use case,
>> that's a hint to consider if that use case is precisely the best way
>> to compose what you want to do.
>>
>> Anyway, I'm pretty sold on SizeConstants, so I'm hoping to stay with
>> that, are you OK with it?
>
> Yes, as mentioned on my v4 review. I agree `SizeConstants` describes
> what this trait provides currently - but was also thinking that this
> trait might grow into depending on some arithmetic operations to allow
> generic code to be written for anything that is a size in the general
> sense.

We can always rename it when we need to grow the trait. We can leave
bikeshedding to the future.

Best,
Gary

>
> That being said, we can also write said generic code by depending on the
> required ops explicitly, so limiting the trait to providing constants
> doesn't really limit us.