#Compiler is not complaining about the return types, why?

7 messages · Page 1 of 1 (latest)

fringe fulcrum
#

I have this code https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6729c9584282aed7a1a89786a49dd27c which compiles and I don't know why because the return types are different.

On one side I have fn stream_string() -> impl Stream<Item = String>
But on the other side I have:

    async fn get_log(&self) -> Pin<Box<dyn Stream<Item = Self::Item>>> {
        Box::pin(stream_string())
    }

Which returns stream_string() but they return different things (one is impl and the other is dyn)?

Why is the compiler not complaining about this?

quasi topaz
fringe fulcrum
#

where in the documentation can I read about that?

quasi topaz
#

?play

use std::fmt::Display;

fn foo<'a>(s: impl Display + 'a) -> Box<dyn Display + 'a> {
    Box::new(s)
}
lofty dirgeBOT
fringe fulcrum
#

so impl has nothing to do here, the coertion is from Sized to dyn ?