gamedig / rust-gamedig

Game Server Query Library.
https://crates.io/crates/gamedig
MIT License
39 stars 12 forks source link

crate: Tidy up some out of place types #160

Closed Douile closed 9 months ago

Douile commented 10 months ago

My main aim here was to move types that are likely to be used by consumers of the library into the root scope of the library. I'm not sure if this is good practice but I thought it would be helpful:

TimeoutSettings and ExtraRequestSettings are now just in gamedig:: so users using generic query don't need to delve deep into the protocol type module.

use gamedig::{query_with_timeout_and_extra_settings, TimeoutSettings, ExtraRequestSettings, GAMES};

pub fn main() {
  let game = GAMES.get("teamfortess2").unwrap();
  let timeout = TimeoutSettings::new(/*...*/);
  let extra = ExtraRequestSettings::default();
  query_with_timeout_and_extra_settings(/*...*/);
}

I also moved the generic query functions, they should never have been in in the games/mod.rs file in the first place, although I'm not sure whether it would be better for them to be in games/query.rs or maybe even protocols/query.rs.

Where possible I added deprecation warnings in the old place, so the aliases can be removed in the future.

CosminPerRam commented 10 months ago

Hey, sorry for responding so late to this. I do think that moving (or re-exporting) those types would be great for usage, but wouldn't just having

pub use protocols::types::{ExtraRequestSettings, TimeoutSettings};

in lib.rs be the same thing? Hope I don't miss on anything.

I also moved the generic query functions, they should never have been in in the games/mod.rs file in the first place, although I'm not sure whether it would be better for them to be in games/query.rs or maybe even protocols/query.rs.

Well said, I would say it would be better in games/query.rs.

Douile commented 10 months ago

in lib.rs be the same thing? Hope I don't miss on anything.

Yes this would be same for library consumer, but I was also thinking it might be better for maintaining if the files are more organized (I'm not sure if the way I've done here is actually more organized).

Well said, I would say it would be better in games/query.rs.

Yeah, that makes more sense, especially since each game no longer has its own file.

CosminPerRam commented 10 months ago

(I'm not sure if the way I've done here is actually more organized)

I wouldn't think so. They are primarily used for protocols, so I think they belong in the protocols folder. But I do think that the types file is a bit too cluttered, I think it could benefit of some extraction, thoughts?

Douile commented 9 months ago

So move from the games mod.rs to query.rs and types.rs. Yeah I agree the placement of ExtraRequest and TimeoutSettings isnt better. Im not sure where they are currently is the best place but I don't think where I moved them is better. So I'll leave that as is and just add re-exports in the root of the library to make consumption easier.