383 karma · joined December 9, 2016
It's important to note that lifetimes are not just for the compiler. They are also documentation / API contracts:
fn add_to_vec<'a>(element: &'a str, vec: &mut Vec<&'a str>) { ... }
This documents that the vec passed into the function can't outlive the element that's passed in. That's because the string (a reference (pointer) to the string data) that's passed in gets stored in the vec. So freeing the string and then using the vec would result in a use after free.
You can't have this power without a syntax for it. You could of course do some global analysis, but now you can't have API contracts like this anymore, which are important for semantic versioning.
An alternative syntax a language could use would be to have arbitrary pre- and post-conditions that the compiler can verify, which would be a whole lot more powerful, but also a lot more wordy than the short lifetime "tags" that Rust uses.
You could even align it with a DST transition in countries that have those where you simply skip one to apply the change.
Though you are right in that I don't know of a built-in way to count Unicode Scalar Values (USVs).
Or even WebAssembly (though more of an experiment than anything): https://github.com/harfbuzz/harfbuzz/blob/main/docs/wasm-sha...
The only real need for JS would be to initialize the wasm module in the first place.
While yes, that's really bad, it's just temporary build files. The actual executable should be fairly tiny.
In Rust an async function is really just a const fn that synchronously only constructs and returns a state machine struct that implements the Future trait.
So
async fn foo(x: i32) { }
essentially desugars to
const fn foo(x: i32) -> FooFuture { FooFuture { x } }
struct FooFuture { x: i32 } // technically it's an enum modelling the state machine
impl Future for FooFuture { ... }
You have to explicitly spawn that onto a runtime or await it (i.e. combine it into the state machine that your code is already in). So that's actually really cool about how Rust handles async; that an async fn really isn't doing any magic, it just constructs a state machine and never interacts (or spawns) with a runtime at all, so it never starts running in the background, you are always in full control. And by throwing the future away, you are essentially cancelling it, there's no need to interact with any runtime either.
undefined is not an object (evaluating 'navigator.wakeLock.request')
Update: Turns out it's only available behind HTTPS. The PWA bug might be related.
I just played around with it today again and I immediately ran into like 5 bugs with font matching until I found out that there's not even an implementation for font matching other than "every property has to match 100%" (and if not, it falls back to an emoji font which is another bug), so there's not even the basic CSS font matching algorithm implemented (and the state of the fallback algorithm might be even worse then, as unlike the nicely documented CSS font matching algorithm, the latter is the undocumented hard part).
> does AssemblyScript allow the same control over memory layout as C, C++ or Rust?
There's no UB, so in a way AssemblyScript is almost more low level than those, as you have full control over the memory and instructions.