-
Notifications
You must be signed in to change notification settings - Fork 17
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
PlayerFinder iterator #64
Comments
The lifetimes were the original cause for me to not being able to implement the trait initially.
However, I'm leaning towards just using owned types in There might also be a fourth option, which is to have an iterator of a new type that can then be converted into the real If you just want to compare the name of the player against some sort of config file or regex, then it would suffice. If you want to check what each of them is doing, then it's not. |
Sorry for taking this long to respond. Switching away from I kinda like the idea of creating a "dummy Player" that the iterator would yield instead of the actual struct DummyPlayer {
bus_name: String,
connection: Rc<PooledConnection>,
}
impl DummyPlayer {
fn initialize(self) -> Result<Player, DBusError> {
Player::for_pooled_connection(self.connection, self.bus_name, ...)
}
} The problem is that at that point we are basically just iterating over a The other thing I want to ask is how the iterator itself will work. The simplest solution is to just call |
Good thoughts. I've commented your approach in #66, and it looks good to me. |
As mentioned in #57,
PlayerFinder
would ideally have a way to iterate over the players found. This would make it easier for users to create their own filters by checking each player without the need to create aVec<Player>
. The problem with this is that currently (as far as I know) it's not possible to implement theIterator
trait that would yield a struct with a named lifetime because "generic associated types" are not yet supported. There are 3 solutions to this:Player
Iterator
traitThe first option would be ideal but there's no telling when it will happen (it's been in the works for at least 5 years now).
The second option can be done now but has a drawback. It would require changing
Player.dbus_name
andPlayer.path
into something else, likeString
which seems like a fine replacement since bothBusName
andPath
are basically just wrappers aroundCow
. The downside is that every timePlayer.connection_path()
is called theString
s will need to be turned intoBusName
andPath
which sounds less than perfect since they will always be the same. I'm not sure how much of a difference it would realistically make compared to the current implementation which clones the variables each time but it will probably be worse. One possible solution would be to makeconnection_path()
a separate function and try to use some sort of cache but that sounds very awkward.The last option is to just let the iterator struct have a
next_player(&mut self) -> Option<Result<Player, DBusError>>
method. You wouldn't be able to use it in a for loop but you could do awhile let
loop. This would also lose out on all of the provided methods that come withIterator
There is a 4th option and that's switching away from
dbus-rs
but that's a whole different topic that might not even solve this problem in the end.The text was updated successfully, but these errors were encountered: