Earlier quoted context omitted.
index out of bounds errors are handled in separate ways depending on the kind of array you are using. If I understand how it works correctly, you can be working with one of three main kinds of arrays: slices with a known length, slices with an unknown length, or a growable vector. In the case of slices with a known length, ie: let a = [0]; then trying to say a[1] is a compile error since the compiler knows the length…
Indexing a fixed-length array (I.e. known at compile time) out of bounds is not prohibited at compile time. All array types trigger a task failure on out-of-bounds access (unless you explicitly opt-in to unchecked indexing).
Rust for C++ programmers – part 3: primitive types and operators
21–30 of 68 posts
Re: Rust for C++ programmers – part 3: primitive types and operators
#22Earlier quoted context omitted.
Kinda, yes, but not really. Currently, the best http framework in Rust is rust-http ( https://github.com/chris-morgan/rust-http ) and it has the things needed for handling requests and sending responses. But as far as actual full featured web frameworks, there is only one that I know of (discounting mre since it hasn't been updated in a long time) and that's because I am the creator of it. oxidize ( https://github.co…
What I like about it is that it's pretty devoid of macros. I'm curious as to how you are planning to handle the environment of the webapp (configuration, connection pool, business objects...), given that you settled for plain functions with a given signature.
Re: Rust for C++ programmers – part 3: primitive types and operators
#23Earlier quoted context omitted.
index out of bounds errors are handled in separate ways depending on the kind of array you are using. If I understand how it works correctly, you can be working with one of three main kinds of arrays: slices with a known length, slices with an unknown length, or a growable vector. In the case of slices with a known length, ie: let a = [0]; then trying to say a[1] is a compile error since the compiler knows the length…
Indexing a fixed-length array (I.e. known at compile time) out of bounds is not prohibited at compile time. All array types trigger a task failure on out-of-bounds access (unless you explicitly opt-in to unchecked indexing).
Re: Rust for C++ programmers – part 3: primitive types and operators
#24Earlier quoted context omitted.
index out of bounds errors are handled in separate ways depending on the kind of array you are using. If I understand how it works correctly, you can be working with one of three main kinds of arrays: slices with a known length, slices with an unknown length, or a growable vector. In the case of slices with a known length, ie: let a = [0]; then trying to say a[1] is a compile error since the compiler knows the length…
> it will cause a task failure i.e. a crash.
Re: Rust for C++ programmers – part 3: primitive types and operators
#25what about rust for webapps? are there any frameworks out there?
Re: Rust for C++ programmers – part 3: primitive types and operators
#26what about rust for webapps? are there any frameworks out there?
The language isn't stable enough yet and there are still a few pieces that need writing, anyway.
Re: Rust for C++ programmers – part 3: primitive types and operators
#27Earlier quoted context omitted.
Indexing a fixed-length array (I.e. known at compile time) out of bounds is not prohibited at compile time. All array types trigger a task failure on out-of-bounds access (unless you explicitly opt-in to unchecked indexing).
Oh thanks for clearing that up! Is there any specific reason why the rust compilier currently doesn't check that a static int accessing into a known length slice doesn't result in a compile error? (I'm only referring to cases where the index you are trying to access is known at compile time as well as the length of the slice)
Probably better to handle all out-of-bounds errors the same way.
Re: Rust for C++ programmers – part 3: primitive types and operators
#28Having been the victim of a fun Javascript bug recently (something like ("1" + 10)*2), I must say that I agree that type coercion is the wrong thing to do 99% of the time (probably with the exception of attempting to divide integers).
Re: Rust for C++ programmers – part 3: primitive types and operators
#29Having been the victim of a fun Javascript bug recently (something like ("1" + 10)*2), I must say that I agree that type coercion is the wrong thing to do 99% of the time (probably with the exception of attempting to divide integers).
Turns out the package expected numbers, but sometimes a bug meant the data source would give arrays (of a single number each), the package's own max (using <) would perform a lexical comparison (comparison would coerce to string and a graph with a value at 800 and one at 1800 would pick a y-scale for 800 and cut off 1800) but further operations would coerce to number, so there was no error anywhere and most graphs looked correct.
Re: Rust for C++ programmers – part 3: primitive types and operators
#30Earlier quoted context omitted.
Yes, Java applications are rarely killed by the OS/memory manager for trying to access memory they don't have control over.
That's a strange definition of "crash" you have there. I should go tell my customers next time that their programs definitely didn't crash.
Granted, it is very rare that you can/should recover from nullpointer or OOB exceptions anyway. What you can do though is try to clean up things, show a polite message and shut down the application in a semi-controlled way.
"Preventing crashes" isn't the best description of Rust's novel protection systems. In my opinion, the best part is providing guarantees about data integrity and security, e.g. preventing heartbleed type read-overruns and preventing data races in concurrent code due to shared mutable state.