Is the pure existance of a `&[u32]` and `&mut [u32]` to the same data already considered undefined behaviour?

I am in the process of implementing an SPI driver. Now I have the following driver code (MRE-ified): use tokio::{join, sync::mpsc}; async fn spi_transmit(write_buf: &[u32], read_buf: &mut [u32]) { assert_eq!(read_buf.len(), write_buf.len()); let (write_fifo, mut read_fifo) = mpsc::channel(2); let write_task = async { // Simulate an SPI bus that respondes with the sent data + 20,… Read More Is the pure existance of a `&[u32]` and `&mut [u32]` to the same data already considered undefined behaviour?

How to join a sequence of tuples, each with its own sequence?

I have a sequence of tuples where each tuple contains another sequences. To better illustrate the problem, please have a look at the below snippet (Rust Playground): fn main() { let data = [ (vec![1, 2, 3], vec![‘a’]), (vec![4, 5, 6], vec![‘b’, ‘c’]) ]; let res: (Vec<i32>, Vec<char>) = data…? // res = (vec![1, 2,… Read More How to join a sequence of tuples, each with its own sequence?

Deserialize json into enum

I am trying to deserialize a json but i am unable to get the expected result. Below is my code: use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] struct StudentData{ stu1: TestResult, stu2: TestResult, stu3: TestResult, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] enum TestResult{ #[serde(rename = "fail")] Fail, #[serde(rename = "absent")] Absent, Pass(String) } fn main()… Read More Deserialize json into enum

Rust – Add array in reqwest::blocking::multipart::Part

I need to send an array of images to an API using form-data, so I’m using a loop to add the images, but I’m getting an error. fn main() { let json = r#"{ "imgupload": ["/home/user/Pictures/image01.jpg", "/home/user/Pictures/image02.jpg"] }"# .to_string(); let request = serde_json::from_str::<ProductRequest>(json.as_str()).unwrap(); let mut form = reqwest::blocking::multipart::Form::new(); let array = request.imgupload.unwrap(); for file_path in… Read More Rust – Add array in reqwest::blocking::multipart::Part

Program hangs on channel rx

Could somebody explain, why if I remove the "move" from for_each, the program hangs? use std::sync::mpsc::channel; fn main() { let v = vec![0,1,2,3,4,5,6,7,8,9]; let (tx, rx) = channel(); v.iter().for_each(move |&elem| { tx.send(elem).unwrap(); }); println!("Tx’ed"); let rx_vec: Vec<_> = rx.iter().collect(); println!("Collected into vec"); } >Solution : The code hangs without move because in that variant tx… Read More Program hangs on channel rx