play.rust-lang.org Rust Playground A browser interface to the Rust compiler to experiment with the language Hi! I'm trying to understand the compiler error, see some ambiguity here. Perhaps it's just a language issue. English isn't my native. If I…
As someone who is not professionally a programmer or officially educated as such, I am about two to three months into learning Rust, and most concepts I have been able to slowly reason my way through. Something I have been stuck on for a while now,…
Warning: This is a half-baked idea. There are many soundness issues with specialization in its current form. I would like to propose an alternative. While it may not be as powerful, it should be sound due to its simplicity. where clause statement…
I have a struct: struct DocPos { block: Uuid, offset: usize, flags: u32 } And lots of functions around it, for example: fn doc_pos_to_utf16_index(pos: DocPos) -> Utf16Index fn compare_positions(&self, a: &DocPos, b: &DocPos) -> Ordering But they…
I have the following snippet (minimization of a similar problem encountered in real code): const N: usize = 32; fn read(block: &[u8; 8 * N]) -> [u64; N] { let (chunks, tail) = block.as_chunks(); assert!(tail.is_empty()); let mut block = [0u64; N];…
I'm learning Rust and trying to understand the difference between compile-time errors and runtime panics when accessing array elements. Consider the following code: fn main() { let a: [u32; 5] = [1, 2, 3, 4, 5]; let b = [1, 2, 3]; println!("b is…
I think this code ought to be sound but I couldn't find a good resource to prove so: #[repr(C)] pub struct Foo<B> { payload: B, version: u8, } impl<'a> Borrow<Foo<&'a [u8]>> for Foo<Box<[u8]>> { fn borrow(&self) -> &Foo<&'a [u8]> { unsafe { &*(self…
hi folks! why does an assoc type with a Self: Sized bound non dyn usable? (I just crammed this fact and I don't know why exactly does it work this way....) trait Trait { type Foo where Self: Sized; fn foo(&self) -> Self::Foo where Self: Sized; fn…
I have a three-dimensional array like this: const XDIM = 60; const YDIM = 60; const ZDIM = 2; let mut world = [[[0.0; ZDIM] ; YDIM]; XDIM]; How would I extract all the X and Y contents for a single Z-value, giving me something like a variable of the…
So I'm doing a silly thingy, with a HashMap keys of Vectors of references. I probably shouldn't, but am. During the program I wanted to get user input, find the key in the hashmap that matches, and store a reference to said key. It'd be lifetime…
I try to implement my own Serde deserializer for my non-default parsing problem. It is an educational project to sharpen my Rust skill, which means that I have real world use case, but my focus is on really understanding what's going on. I'll try to…
I've run into a problem formatting terminal output. I'm using the ansi_term and tabled crates together. Here's a minimal example: use ansi_term::Style; use tabled::{Table, Tabled}; #[derive(Tabled)] struct Row { column: String, } fn main() { let…