Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pseudorandom name
May 6, 2007

Firefox has been shipping a Rust MP4 container parser for a while now.

Adbot
ADBOT LOVES YOU

pseudorandom name
May 6, 2007

const test: f64 = 1. * 10.; works because you aren't trying to call a method on an unknown type.

const ELECTRON_MASS: f64 = 9.109390 * (10.).powi(-31); fails because you're trying to do a method lookup on some kind of floating point type, but the compiler doesn't know which one yet, hence the error.

If you change it to something that isn't ambiguous, like const ELECTRON_MASS: f64 = 9.109390 * 10.0f64.powi(-31);, the error becomes
code:
error[E0015]: calls in constants are limited to tuple structs and tuple variants
 --> src/lib.rs:1:39
  |
1 | const ELECTRON_MASS: f64 = 9.109390 * 10.0f64.powi(-31);
  |                                       ^^^^^^^^^^^^^^^^^
  |
note: a limited form of compile-time function evaluation is available on a nightly compiler via `const fn`
 --> src/lib.rs:1:39
  |
1 | const ELECTRON_MASS: f64 = 9.109390 * 10.0f64.powi(-31);
  |                                       ^^^^^^^^^^^^^^^^^

error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

pseudorandom name
May 6, 2007

std::vec::Vec::into_boxed_slice()

pseudorandom name
May 6, 2007

notwithoutmyanus posted:

I'm trying to wrap my head around this:

code:
fn main() {
    let mut a: [i32; 6] = [10, 20, 30, 40, 50, 60];
    println!("a: {a:?}");

    let s: &[i32] = &a[2..4];

    println!("s: {s:?}");
}


That part that throws me off is: let s: &[i32] = &a[2..4]; . Wouldn't specifying that you're borrowing cells 2-4 print out 20 30 and 40, not just 30 and 40? I know I'm wrong/missing something here, so why am I wrong?

Arrays are zero-based, the element at offset 2 is the third element in the array.

pseudorandom name
May 6, 2007

BitTorrent uses Bencode and Bencode already has a serde implementation.

It’s really easy to use a serialization library with a serialization format, especially when the work has already been done for you. Not so much for ad hoc bit twiddling.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply