Skip to content

Instantly share code, notes, and snippets.

Avatar

Ugo Varetto ugovaretto

  • The Pawsey Supercomputing Centre
  • Kensington, Western Australia
View GitHub Profile
View Cargo.toml
[package]
name = "memcpy"
version = "0.1.0"
edition = "2021"
[dependencies]
page_size = "*"
nix = "*"
@ugovaretto
ugovaretto / aligned_vec.rs
Created Jun 7, 2022
Create aligned Vec instance
View aligned_vec.rs
// 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 {
@ugovaretto
ugovaretto / aio_read.rs
Created Jun 6, 2022
Async file I/O with aio* functions
View aio_read.rs
// 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(),
@ugovaretto
ugovaretto / read_at.rs
Created May 19, 2022
read_at with Rust
View read_at.rs
#[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))]
View rust_tokio_block_in_place.rs
use std::{
fs::File,
io::{Read, Write},
time::Instant,
};
use tokio::task::{self, JoinHandle};
async fn compute() {
let handles: Vec<JoinHandle<_>> = (0..1000)
.map(|_| {
@ugovaretto
ugovaretto / Cargo.toml
Created May 1, 2022 — forked from Ciantic/Cargo.toml
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
View Cargo.toml
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
View rust-tip-rust-analyzer-customization.md
@ugovaretto
ugovaretto / README.md
Created Apr 24, 2022 — forked from PurpleBooth/README.md
A github workflow pipeline for rust that does test, build and deploy windows, linux and mac, creates releases, and does SemVer Versioning, and releases to a homebrew tap
View README.md

Features

  • Automatically bump SemVer
  • Update a personal homebrew tap
  • Keep that pesky version in the Cargo.toml up to date
  • (From dependabot) Get new versions out as soon as possible

Assumptions

  • You don't want a changelog
@ugovaretto
ugovaretto / work_queue.rs
Created Apr 19, 2022 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
View work_queue.rs
// 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:
@ugovaretto
ugovaretto / Cargo.toml
Last active Apr 13, 2022
Upload data into S3 bucket with AWS Rust S3 SDK
View Cargo.toml
[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" }