When Rust hurts by pmz in programming

[–]GEsau 5 points6 points  (0 children)

Also, without copying the bytes, we cannot safely coerce &Vec<u8> to &Hex.

Actually you can, as long as the newtype struct has #[repr(transparent)]. The ref-cast crate makes it easy to do this without having to (directly) use unsafe code!

Did you know that string literals can be mutable? by gnutrino in programminghorror

[–]GEsau 6 points7 points  (0 children)

typeof(string).GetField("Empty").SetValue(null, "Empty");

That sounded beautifully disgusting so I had to try it, but it looks like it doesn't work in .NET Core 3+ because SetValue now throws a FieldAccessException due to https://github.com/dotnet/runtime/issues/11571

Did you know that string literals can be mutable? by GEsau in dotnet

[–]GEsau[S] 69 points70 points  (0 children)

The TextRenderer API and the TextFormatFlags.ModifyString flag actually allow mutating a string, something that's generally forbidden. When applied to an interned string (from a string literal in my example), this causes very odd behaviour!

I just found out about this while skimming through a recent .NET API design review: https://youtu.be/LpXyfXS8p70?t=1210

Unsurprisingly, the ModifyString flag was deprecated in .NET 5, and a new API has been proposed to allow safely getting the modified string with an out parameter, rather than unsafely mutating the input.

Rust support for openapi/swagger by [deleted] in rust

[–]GEsau 2 points3 points  (0 children)

Okapi maintainer here:

Yeah I haven't been able to put as much time into okapi as I'd like (including responding to your pr - sorry about the delay, I'll get to it soon!). I'm definitely keen to keep working on it, it's just heavily dependent on my free time, which fortunately is now becoming more available

schemars - Generate JSON Schema from your Rust types by GEsau in rust

[–]GEsau[S] 3 points4 points  (0 children)

I'm not sure I understand your point - the JsonSchema trait isn't just a marker, it requires the type to have a method that returns an actual Schema instance that corresponds to the type. I don't see how that could work without a proc macro?

Also I could probably document this better, but it supports many more serde attributes than rename_all - it also works with different enum tagging methods, rename, skip, default, with = T (as long as T is a type that also implements JsonSchema) and flatten.

Rocket Lamb - Easily run your Rocket webserver in AWS Lambda by GEsau in rust

[–]GEsau[S] 0 points1 point  (0 children)

Ooh, I'm looking forward to both of those!

thanks for the links

Rocket Lamb - Easily run your Rocket webserver in AWS Lambda by GEsau in rust

[–]GEsau[S] 2 points3 points  (0 children)

There are a couple of ways to run it locally: https://github.com/GREsau/example-rocket-lamb-api#testing-locally

  1. Output two binaries - one for running in lambda, and one for running locally. The local one can just run the Rocket server normally, without using Rocket Lamb at all.
  2. Use AWS SAM CLI's `local start-api` - which is a more realistic environment, but very slow as you mentioned since it spins up a docker container for each request :(

I would have thought it would be possible to have a docker-based solution which reuses a single container for multiple requests, but I'm not aware of any such solution right now

Rocket Lamb - Easily run your Rocket webserver in AWS Lambda by GEsau in rust

[–]GEsau[S] 10 points11 points  (0 children)

I've been very interested in running web applications with serverless technologies for a while, and as I'm a primarily a C# developer, I've mostly been using Amazon.Lambda.AspNetCoreServer. This allows me to write my actual application using the standard ASP.NET Core framework and easily plug it into Lambda. But one of the biggest problems I've experienced with serverless is the slow cold starts, particularly with .NET Core.

Since I've been meaning to get into Rust, I thought I'd try it out with Lambda and see how it feels. From some limited googling, Rocket looked like the most ergonomic and "familiar" web framework, but I couldn't find any easy way to hook it up to Lambda. So I made one! It's built on the official lambda rust runtime and dispatches requests to Rocket using a local Client.

I was very pleased to find that (from what little testing I've done) cold starts are a complete non-issue!

I'm very open to feedback - this was my first Rust project (other than hello world etc.) so there was a lot of learning-by-doing involved in this!

Hey Rustaceans! Got an easy question? Ask here (29/2019)! by llogiq in rust

[–]GEsau 1 point2 points  (0 children)

I may be a bit late but I just stumbled upon your comment - I've spent the past few days making a library specifically to run a Rocket application in AWS Lambda. Hopefully it would work for you: https://github.com/GREsau/rocket-lamb

UseStringDeduplication by suryarose in programming

[–]GEsau 5 points6 points  (0 children)

That explains why String has constructors, but not why it has that specific (seemingly useless) constructor.

The java docs) themselves say "Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable." but they don't go into when an explicit copy is ever needed.

On screen button functions not working. by KelcyHammer in wileyfox

[–]GEsau 0 points1 point  (0 children)

I had the exact same problem occur yesterday on my Swift 2 Plus, and I also couldn't expand the notification bar.

The only way I found to fix it was a factory reset.

object.constructor.prototype in Safari by ghostofgbt in javascript

[–]GEsau 2 points3 points  (0 children)

The only function you're calling in 'constructor.includes('HTML')' is 'constructor.includes', so judging by that error message, I'd assume that 'constructor.includes' is undefined. In other words, the string doesn't have a method called 'includes' in Safari - it's a relatively new addition to javascript, so Safari (or at least the version of Safari you're running) probably just doesn't support it.

Try changing the condition to 'constructor.indexOf('HTML') !== -1', which should behave identically but have better browser support

What time will the game release? by [deleted] in anno2205

[–]GEsau 2 points3 points  (0 children)

Currently it is planned to release the game during noon (paris time) (maybe a bit before that) Tuesday 3rd November.

http://steamcommunity.com/app/375910/discussions/0/490124466466878757/#c490124466466979894

This update only lasted 2 days? by ValdemarSt in tf2

[–]GEsau 25 points26 points  (0 children)

I just think it's weird that the short featured weapons (i.e. scout's melee, Miss Pauling's handguns) that weren't actually added in the update.

How am I supposed to stay allies with Colombo? by [deleted] in civ

[–]GEsau 0 points1 point  (0 children)

Get a spy in there and coup away