3 ms·
In the Rust code, where is the Result type they're using defined? I assume that the parameterless `Result` return types are intended to be `Result<()>`, and I s
by saghm 5y ago
In the Rust code, where is the Result type they're using defined? I assume that the parameterless `Result` return types are intended to be `Result<()>`, and I suppose it might be possible to achieve this with default generics, but I've never seen that used before, so it sticks out as a bit odd to me.
- nicoburns 5y agoI see they're importing `kernel::prelude::*`, so I would guess there.
- swsieber 5y agoIt looks like something like that is indeed possible. See a post on the rust internals forum where that's setup with a type alias. It was called `Fallible` in that post, but it's common in the Rust ecosystem to override the default Result type with a custom error parameter but still calling it Result. https://internals.rust-lang.org/t/make-stds-result-a-type-alias-with-default-type-parameters/4619/5 https://internals.rust-lang.org/t/make-stds-result-a-type-al... So I'd guess in this driver that the Result type being used is a type alias defined in the prelude that's glob imported.
- saghm 5y ago> it's common in the Rust ecosystem to override the default Result type with a custom error parameter but still calling it Result. Yep, I do that all the time! I never considered putting a default value for the parameter though
- dexwiz 5y agoLook's like kernel::Result does just that. It is re-exported as part of the prelude. https://rust-for-linux.github.io/docs/kernel/type.Result.html https://rust-for-linux.github.io/docs/kernel/type.Result.htm...
- saghm 5y agoInteresting! TIL
- GolDDranks 5y agoIs that doc old? It doesn't include `kernel::device` and many other modules/types that are imported in the code.
- tialaramex 5y agoWell, I guess it might be more reasonable to say kernel::device is very new. The person who mailed in this work hasn't landed it in the Rust for Linux kernel from which the documentation is built. We're seeing the code that the new person wants to check is roughly OK before they raise a PR, whereas those docs are built from the repo that PR would be against.