Rust-Analyzer Customization Tips
Customize mutable style
Video - Rust Tip - Customize Mutable Colors in VSCode
In the settings.json
add the following:
"editor.semanticTokenColorCustomizations": {
[package] | |
name = "memcpy" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
page_size = "*" | |
nix = "*" |
// Create aligned Vec | |
fn main() { | |
let ivec: Vec<i32> = aligned_vec(2048, 4096, 256); | |
assert!(ivec.as_ptr() as u64 % 256 == 0); | |
} | |
pub fn aligned_vec<T: Sized>(size: usize, capacity: usize, align: usize) -> Vec<T> { | |
unsafe { | |
if size == 0 { | |
Vec::<T>::new() | |
} else { |
// Async file I/O | |
use libc::{aio_read, aiocb, aio_error, aio_return}; | |
use std::fs::File; | |
use std::os::unix::io::AsRawFd; | |
fn main() { | |
let file = File::open("src/main.rs").unwrap(); | |
let mut buf = [0; 1024]; | |
let mut cb = aiocb { | |
aio_fildes: file.as_raw_fd(), |
#[cfg(any(windows))] | |
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) { | |
use std::os::windows::fs::FileExt; | |
let mut data_read = 0; | |
while data_read < buffer.len() { | |
data_read += file.seek_read(buffer, offset).unwrap(); | |
} | |
} | |
#[cfg(any(unix))] |
use std::{ | |
fs::File, | |
io::{Read, Write}, | |
time::Instant, | |
}; | |
use tokio::task::{self, JoinHandle}; | |
async fn compute() { | |
let handles: Vec<JoinHandle<_>> = (0..1000) | |
.map(|_| { |
[package] | |
name = "yourpackage" | |
version = "0.1.0" | |
authors = ["John Doe"] | |
edition = "2018" | |
[[bin]] | |
name = "example" | |
path = "stream-a-file-using-rust-hyper.rs" |
Video - Rust Tip - Customize Mutable Colors in VSCode
In the settings.json
add the following:
"editor.semanticTokenColorCustomizations": {
// Here is an extremely simple version of work scheduling for multiple | |
// processors. | |
// | |
// The Problem: | |
// We have a lot of numbers that need to be math'ed. Doing this on one | |
// CPU core is slow. We have 4 CPU cores. We would thus like to use those | |
// cores to do math, because it will be a little less slow (ideally | |
// 4 times faster actually). | |
// | |
// The Solution: |
[package] | |
name = "Upload to S3" | |
version = "0.1.0" | |
authors = ["Ugo Varetto <ugo.varetto@csiro.au>"] | |
edition = 2021 | |
[dependencies] | |
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" } | |
# snippet-start:[s3.rust.s3-object-lambda-cargo.toml] | |
aws-endpoint = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" } |