How to return the socket connection object and its type?

I'm trying to connect to a server using websockets. So once after the connection is established, I am trying to return that connection object. But I'm unable to find the correct return type for it.
socket-connection

In this I'm trying to return the "client" variable. Can someone please let me know about the return type for this?

You can let the compiler tell you the type by intentionally declaring it as the wrong type:

let my_value: ()  = "hello".to_string();

See playground

(also, use triple-backticks ``` to show code so it's more legible for different devices)

If you make another variable of a type that you know and then try to put the unknown variable into the known variable type, the error message will tell you both types.

fn main() {
    let mut x: i32 = 4; // We know x is i32
    let y = "what is y";
    x = y; // note error message will tell you type of both x and y

    println!("{} {}", x, y);
}

Will give you this error telling you the unknown type of 'y'

error[E0308]: mismatched types
 --> src/main.rs:4:9
  |
2 |     let mut x: i32 = 4; // We know x is i32
  |                --- expected due to this type
3 |     let y = "what is y";
4 |     x = y; // note error message will tell you type of both x and y
  |         ^ expected `i32`, found `&str`

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.