*rubbing eyes* Anyone use "Rocket"?
-
@mcc As someone who has never tried Rust, I honestly can't tell if you're joking or not.
-
@mcc As someone who has never tried Rust, I honestly can't tell if you're joking or not.
@ryan This is literally a real thing in Rust but it's not called the wink operator. It does involve typing the characters <'_>.
Literally what it means: In Rust, every variable has a "lifetime" associated with it. Sometimes, you must explicitly tell the compiler what the lifetime is. But often, in this case, you can type <'_> which means "compiler, please figure out the lifetime for me". And often it succeeds.
-
*rubbing eyes* Anyone use "Rocket"?
The worst/most Ruby-like thing about Rocket is when you return a value from a Route function, you just kinda return… whatever datatype you want, and Rocket figures it out.
Unless it doesn't, and you have *no* idea what to return.
For a string, you return a String.
What do I return for bytes? It's not a string, it's a &[u8; 1335895] and it's not valid UTF-8. Do I return a rocket::response::ByteStream? That seems to be the correct answer but doesn't work
@mcc It seems that the `Stream` part (https://api.rocket.rs/v0.5/rocket/response/stream/) of the return type to be returned is actually supposed to be a type utilizing the `futures::stream::Stream` trait (https://docs.rs/futures/0.3.31/futures/stream/trait.Stream.html) internally, and all the wrapper types mentioned are basically "convenience wrappers" which implement the stream upon something else, and futhermore wrap it into a `rocket::responder::Responder` (https://api.rocket.rs/v0.5/rocket/response/trait.Responder), which furthermore also does the error handling, like a monad...
-
@mcc It seems that the `Stream` part (https://api.rocket.rs/v0.5/rocket/response/stream/) of the return type to be returned is actually supposed to be a type utilizing the `futures::stream::Stream` trait (https://docs.rs/futures/0.3.31/futures/stream/trait.Stream.html) internally, and all the wrapper types mentioned are basically "convenience wrappers" which implement the stream upon something else, and futhermore wrap it into a `rocket::responder::Responder` (https://api.rocket.rs/v0.5/rocket/response/trait.Responder), which furthermore also does the error handling, like a monad...
@mcc It feels like the easiest way to implement some custom borrowing strategy would be to "just" return a custom type that implements the `Responder` trait, and move most of the logic into that, at least as long as you don't need a complicated self-referential state machine to produce the output...
-
Update: .to_slice() was the magic solution. I need to remember to put this in my "things to try at random when Rust isn't working" along with typing <'_>.
@mcc Oh right, I keep forgetting Rust can't implicitly cast &[u8, N] to &[u8] for some reason
-
@fishidwardrobe I don't find a method named "pack" on String?
@mcc i beg your pardon. Array#pack -> String; String#unpack -> Array
-
@mcc i beg your pardon. Array#pack -> String; String#unpack -> Array
@fishidwardrobe I'm sorry: Do you understand that we are talking about the Rust programming language, and Ruby is mentioned because the Rocket library for Rust is heavily inspired by Ruby design philosophies? I now see I did not mention Rust specifically.
-
@mcc Oh right, I keep forgetting Rust can't implicitly cast &[u8, N] to &[u8] for some reason
-
undefined oblomov@sociale.network shared this topic
-
@fishidwardrobe I'm sorry: Do you understand that we are talking about the Rust programming language, and Ruby is mentioned because the Rocket library for Rust is heavily inspired by Ruby design philosophies? I now see I did not mention Rust specifically.
@mcc ah. no. shutting up now, sorry.
-
@mcc ah. no. shutting up now, sorry.
@fishidwardrobe I now understand the conversation again