*rubbing eyes* Anyone use "Rocket"?
-
*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 i'm going to guess you could String#pack a binary, and use a string as the return?
-
@mcc i'm going to guess you could String#pack a binary, and use a string as the return?
@fishidwardrobe I don't find a method named "pack" on String?
-
In the docs, ByteStream has a generic argument. However the generic argument's meaning is not documented (it's just "S"). The documentation appears to suggest, rather than filling in this S, using a macro. The macro is not doing what I expect. https://api.rocket.rs/v0.5/rocket/response/stream/struct.ByteStream
I can't tell if Rocket has a specific place to go ask for support requests, unless it's the general Rust programming discord, or here.
@mcc It looks like you're passing a reference to an array (`&[u8; N]`) where the signature expects a reference to a slice (`&[u8]`). Try adding an explicit `.as_slice()` to the array expression.
In general this shouldn't be necessary because `[u8; N]` implements `AsRef<[u8]>`. This is what `ByteStream`'s docs describe as the requirement for the type inside the stream, so… ¯\_(ツ)_/¯
(Caveats: I don't use Rocket, I have no idea what's happening inside that macro, and I can't see the call site.)
-
*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 i was going to say yes but instead i am forced to say that there are too many pieces of software called rocket
-
In the docs, ByteStream has a generic argument. However the generic argument's meaning is not documented (it's just "S"). The documentation appears to suggest, rather than filling in this S, using a macro. The macro is not doing what I expect. https://api.rocket.rs/v0.5/rocket/response/stream/struct.ByteStream
I can't tell if Rocket has a specific place to go ask for support requests, unless it's the general Rust programming discord, or here.
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 i was going to say yes but instead i am forced to say that there are too many pieces of software called rocket
@halcy if you try to search for rust you mainly find stuff about a video game. the video game contains rockets. it also has a number of discords. so if you want to know if there's a discord for the rust rocket library…
-
In the docs, ByteStream has a generic argument. However the generic argument's meaning is not documented (it's just "S"). The documentation appears to suggest, rather than filling in this S, using a macro. The macro is not doing what I expect. https://api.rocket.rs/v0.5/rocket/response/stream/struct.ByteStream
I can't tell if Rocket has a specific place to go ask for support requests, unless it's the general Rust programming discord, or here.
@mcc It says S should be a Stream, and ByteStream only implements the Responder trait when S: Send + 'r + Stream, S::Item: AsRef<[u8]> + Send + Unpin + 'r,
So you can do ByteStream::from(futures::stream::once(your_buffer))
-
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 <'_>.
<'_> in Rust is the "Wink" operator. The compiler's like "You can't do that" and you're like "*Wink* Yeah, but you'll let it slide this time, right?"
-
@mcc It says S should be a Stream, and ByteStream only implements the Responder trait when S: Send + 'r + Stream, S::Item: AsRef<[u8]> + Send + Unpin + 'r,
So you can do ByteStream::from(futures::stream::once(your_buffer))
@val Thank you, I'll consider this in future
-
<'_> in Rust is the "Wink" operator. The compiler's like "You can't do that" and you're like "*Wink* Yeah, but you'll let it slide this time, right?"
@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.
-
@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