Open12

the trait `Hoge` is not implemented for `impl std::future::Future` ってなんだ

tkttkt
impl std::future::Future for Hoge {
    
}

こういうのかけってことかな

tkttkt

async trait あたりがいい感じに実装してくれないんだろうか

tkttkt
hidden type for `impl Trait` captures lifetime that does not appear in bounds

note: hidden type `impl std::future::Future` captures lifetime smaller than the function body

前のも特に解決してないけど

tkttkt
use super::check_msg;
use serenity::{
    client::Context,
    model::{channel::Message, id, misc::Mentionable},
};
use songbird::{self, ffmpeg};
use std::path::Path;

pub use crate::model::Voice;

pub async fn join(
    ctx: &Context,
    msg: &Message,
    joiner: Box<dyn Joiner + Send + Sync>,
) -> Result<(), String> {
    Ok(())
}

pub async fn piin(joiner: Box<dyn Joiner + Send + Sync>) -> Result<(), String> {
    joiner.piin().await;
    Ok(())
}
use serenity::async_trait;

#[async_trait]
impl Joiner for Voice {
    async fn join(
        &self,
        connect_to: id::ChannelId,
    ) -> (
        std::sync::Arc<tokio::sync::Mutex<songbird::Call>>,
        songbird::error::JoinResult<()>,
    ) {
        self.manager.join(self.guild_id, connect_to).await
    }
    async fn piin(
        &self,
    ) -> (String,
        String
    ) {
        ("".to_string(), "".to_string())
    }
}

#[async_trait]
pub trait Joiner {
    async fn join(
        &self,
        connect_to: id::ChannelId,
    ) -> (
        std::sync::Arc<tokio::sync::Mutex<songbird::Call>>,
        songbird::error::JoinResult<()>,
    );
    async fn piin(
        &self,
    ) -> (String,
        String
    );
}
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
  --> src/commands/services/join.rs:15:6
   |
15 | ) -> Result<(), String> {
   |      ^^^^^^^^^^^^^^^^^^
   |
note: hidden type `impl std::future::Future` captures lifetime smaller than the function body
  --> src/commands/services/join.rs:15:6
   |
15 | ) -> Result<(), String> {

上のところだけ怒られる

tkttkt
  pub async fn join(
-   ctx: &Context,
-   msg: &Message,
+   ctx: Context,
+   msg: Message,
    joiner: Box<dyn Joiner + Send + Sync>,
  ) -> Result<(), String> {
      Ok(())
  }
tkttkt

こうしたらなおった。
lifetime 合わせないといけなかったのかなとは思うけど、なぜ Future がどうとかで怒られていたのかわからない

tkttkt
the trait bound `impl std::future::Future: commands::services::join::Joiner` is not satisfied

the trait `commands::services::join::Joiner` is not implemented for `impl std::future::Future`

note: required for the cast to the object type `dyn commands::services::join::Joiner`rustc(E0277)
mod.rs(98, 44): the trait `commands::services::join::Joiner` is not implemented for `impl std::future::Future`

呼び出し側でも怒られた
もう何もわからない

tkttkt
  1. a module で Hoge struct を定義
  2. b module で a module の Hoge に b_fn を impl
  3. c module で a module の Hoge を作成 as a_hoge
  4. c module で a_hoge の b_fn を呼び出し

としたら

the trait bound `impl std::future::Future: commands::services::join::Joiner` is not satisfied

the trait `commands::services::join::Joiner` is not implemented for `impl std::future::Future`

note: required for the cast to the object type `dyn commands::services::join::Joiner`rustc(E0277)
mod.rs(98, 44): the trait `commands::services::join::Joiner` is not implemented for `impl std::future::Future`

こういうエラーが起きた?

b_fn is not found とか怒ってほしかった

tkttkt

ちゃんと別で作って検証したいけど、気力が持っていかれたのでまた今度