What exactly is io_uring?

io_uring is a (new as of mid 2019) Linux kernel interface to efficiently allow you to send and receive data asynchronously. It was originally designed to target block devices and files but has since gained the ability to work with things like network sockets. Unlike something like epoll(), it is built around a completion model … Read more

Accept user input

GHJUYGHJKLKUJHM;&MJ:6AG9F5D8V)A8%]>75Q;6EE85U955%-245!/3DU,2TI) M2$=&141#0D% /SX]/#LZ.3@W-C4T,S(Q,”\N+2PK*BDH)R8E)”,B(7Y]?’MZ M>7AW=G5T<W)Q<&]N;6QK:FEH9V9E9&-B86!?7EU<6UI96%=655134E%03TY- Untested, but should work.

How to read a struct from a file in Rust?

Here you go: use std::io::Read; use std::mem; use std::slice; #[repr(C, packed)] #[derive(Debug, Copy, Clone)] struct Configuration { item1: u8, item2: u16, item3: i32, item4: [char; 8], } const CONFIG_DATA: &[u8] = &[ 0xfd, // u8 0xb4, 0x50, // u16 0x45, 0xcd, 0x3c, 0x15, // i32 0x71, 0x3c, 0x87, 0xff, // char 0xe8, 0x5d, 0x20, 0xe7, … Read more

How to do polymorphic IO from either a File or stdin in Rust?

The answer by @A.B. is correct, but it tries to conform to OP’s original program structure. I want to have a more readable alternative for newcomers who stumble upon this question (just like I did). use std::env; use std::fs; use std::io::{self, BufReader, BufRead}; fn main() { let input = env::args().nth(1); let reader: Box<dyn BufRead> = … Read more

How to read (std::io::Read) from a Vec or Slice?

While vectors don’t support std::io::Read, slices do. There is some confusion here caused by Rust being able to coerce a Vec into a slice in some situations but not others. In this case, an explicit coercion to a slice is needed because at the stage coercions are applied, the compiler doesn’t know that Vec<u8> doesn’t … Read more

The best way to get a string from a Writer

If your function accepts an io.Writer, you can pass a *bytes.Buffer to capture the output. // import “bytes” buf := new(bytes.Buffer) f(buf) buf.String() // returns a string of what was written to it If it requires an http.ResponseWriter, you can use a *httptest.ResponseRecorder. A response recorder holds all information that can be sent to a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)