message: Improves the way HasTwo is implemented and add a test for them
diff: @@ -157,38 +157,30 @@ pub trait HasTwo<T, U> {
  fn retrieve_second(&self) -> &U;
  }
  -impl<T, U> HasTwo<T, U> for (&T, &U) {
  +impl<T, U> HasTwo<T, U> for Context
  +where
  + Context: Has<T> + Has<U>,
  +{
  #[inline]
  fn retrieve_first(&self) -> &T {
  - self.0
  + Has::<T>::retrieve(self)
  }
  #[inline]
  fn retrieve_second(&self) -> &U {
  - self.1
  + Has::<U>::retrieve(self)
  }
  }
  -impl HasTwo<Filesystem, GraphicsContext> for Context {
  +impl<T, U> HasTwo<T, U> for (&T, &U) {
  #[inline]
  - fn retrieve_first(&self) -> &Filesystem {
  - &self.fs
  + fn retrieve_first(&self) -> &T {
  + self.0
  }
  #[inline]
  - fn retrieve_second(&self) -> &GraphicsContext {
  - &self.gfx
  - }
  -}
  -
  -#[cfg(feature = "audio")]
  -impl HasTwo<Filesystem, crate::audio::AudioContext> for Context {
  - fn retrieve_first(&self) -> &Filesystem {
  - &self.fs
  - }
  -
  - fn retrieve_second(&self) -> &crate::audio::AudioContext {
  - &self.audio
  + fn retrieve_second(&self) -> &U {
  + self.1
  }
  }
  @@ -378,3 +370,30 @@ impl ContextBuilder {
  Context::from_conf(config, fs)
  }
  }
  +
  +#[cfg(test)]
  +mod tests {
  + use crate::{
  + context::{Has, HasMut, HasTwo},
  + filesystem::Filesystem,
  + graphics::GraphicsContext,
  + ContextBuilder,
  + };
  +
  + #[test]
  + fn has_traits() {
  + let (mut ctx, _event_loop) = ContextBuilder::new("test", "ggez").build().unwrap();
  +
  + fn takes_gfx(_gfx: &impl Has<GraphicsContext>) {}
  + takes_gfx(&ctx);
  + takes_gfx(&ctx.gfx);
  +
  + fn takes_mut_gfx(_gfx: &mut impl HasMut<GraphicsContext>) {}
  + takes_mut_gfx(&mut ctx);
  + takes_mut_gfx(&mut ctx.gfx);
  +
  + fn takes_gfx_fs(_gfx_fs: &impl HasTwo<GraphicsContext, Filesystem>) {}
  + takes_gfx_fs(&ctx);
  + takes_gfx_fs(&(&ctx.gfx, &ctx.fs));
  + }
  +}
  