Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function to enumerate devices #208
base: develop
Are you sure you want to change the base?
Add function to enumerate devices #208
Changes from 1 commit
6a740e3
9bc03d2
629028c
7d9cf3d
6c18b86
737b01d
73e2c2a
d7684be
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this instead return
impl Iterator<Item = io::Result<DrmNode>>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what would be the best approach here.
We can have IO Errors only by failing to open/read the
/dev
directory.For the devices themselves, we will only get errors if they aren't DRM devices, which should be the case for the majority of stuff in
/dev
.Would iterator improve anything in regards to the error handling?
Also, sorry if my answers are a bit confusing. I'm quite new to Rust, so I might be missing the big-picture on how to better handle errors/iterators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be handled with:
And as just mentioned below,
drmGetDevices2()
skips errors while opening sub-devices, so we might as well return an iterator overDrmNode
directly:And as below, on most platforms except FreeBSD we should be reading
/dev/dri
.No worries, I think everyone is happy to educate new contributors on Rust as well as describing the "Rust style" used in drm-rs (as much as we're still discovering what that's supposed to be).
Regarding the
drm_get_devices()
function name (based ondrmGetDevices(2)()
), I'd drop thedrm_
prefix since we're already in thedrm
crate (i.e. a fully qualified call would look likedrm::node::drm_get_devices()
which is somewhat superfluous) and then also drop theget_
prefix because of the noget_
prefix convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the feedback, it's highly appreciated.
I pushed the changes with everything you suggested. Do you mind to give another look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making this a
.map().collect()
rather than a side-effectingfor_each()
? If that, use regular control flow withfor entry in fs::read_dir(..)? { .. }
.The
.collect()
can be dropped if using @notgull's suggestion to return an iterator instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we need to filter the results in some way if we use
.map()
? Asking as we check all devices and likely a lot of them aren't DRM devices, so we need to skip them. This validation is done right now by callingDrmNode::from_path()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such filtering can be implemented by a
.filter_map()
, but I'm hesitant tostat()
every device on the system to see if it is a DRM device.Since
drmGetDevices2()
was requested, I expected this feature to be built after that function. While it does also appear to ignore any error from processing individual devices, this function does openDRM_DIR_NAME
which is/dev/dri
on every platform except FreeBSD where it is/dev
. This way we don't have tostat()
devices that we know won't be DRM devices in the first place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for the pointers. I somehow completely missed the fact that
DRM_DIR_NAME
was different in certain platforms. I will update the code to also use/dev/dri
for all platforms except FreeBSD.