*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
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.
-
*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
as someone with little to no rust awareness I can see myself setting it suggest I stick a "&mut" only to spend about 30 minutes fighting the language to make that work (the language would win)
(I am hoping this doesn't notify mcc since it will be no help to her)
-
*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 Is the source of that slice something like `include_bytes!`? It's being treated as a reference to a fixed-size array rather than a slice (i.e. a runtime length), can you try forcing it to a slice (e.g. by calling `as_slice`) and see if that helps?
The whole stream thing seems to be for cases where you want to be able to start sending response before all of it is ready, but in this case you probably already have all of it
-
*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.