Skip to content

Instantly share code, notes, and snippets.

View tbarusseau's full-sized avatar
🦀
Rust evangelism strike force, one compile error at a time

Thomas Barusseau tbarusseau

🦀
Rust evangelism strike force, one compile error at a time
  • theTribe
  • Rouen, France
View GitHub Profile
/* file.h: */
char thisIsAMethod(int arg1, char *arg2);
/* file.c: */
char thisIsAMethod(int arg1, char *arg2)
{
return arg2[arg1];
}
const char _buf[64] = { 0x02, 0x0b, 0x02, 0x04, 0x42, 0x40, 0x10, 0x42,
0x62, 0x10, 0x42, 0x42, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
fn sum(vector: Vec<i32>) -> i32 {
let mut sum = 0;
for item in vector {
sum = sum + item
}
sum
}
fn sum(vector: &Vec<i32>) -> i32 {
let mut sum = 0;
// vector.iter_mut().map(|e| e.add(1));
// ERROR: cannot borrow `*vector` as mutable, as it is behind a `&` reference
for item in vector {
sum = sum + item
}
fn sum(vector: &mut Vec<i32>) -> i32 {
let mut sum = 0;
vector.iter_mut().map(|e| e.add(1));
for item in vector {
sum = sum + *item
}
sum
@group(0) @binding(0) var<storage, read_write> moon_height_data: MoonHeightData;
fn smooth_min(a: f32, b: f32, t: f32) -> f32 {
let h: f32 = clamp(0.5 + 0.5 * (b - a) / t, 0.0, 1.0);
return mix(b, a, h) - t * h * (1.0 - h);
}
fn smooth_max(a: f32, b: f32, t: f32) -> f32 {
return smooth_min(a, b, -t);
fn find_side_digit(digits: &[&str], line: &str, left: bool) -> usize {
let map = digits.iter().enumerate().flat_map(|(i, d)| {
if left {
if let Some(min_index) = line.find(d) {
Some((min_index, i % 9 + 1))
} else {
None
}
} else {
if let Some(max_index) = line.rfind(d) {
fn compute_result(input: &str) -> u32 {
input
.replace(char::is_alphabetic, "")
.lines()
.map(|l| {
let mut iter = l.chars().flat_map(|c| char::to_digit(c, 10)).peekable();
let first = *iter.peek().expect("no first numerical character");
let last = iter.last().expect("no last numerical character");
struct Game {
game_index: i32,
subsets: Vec<(i32, i32, i32)>,
}
impl TryFrom<&str> for Game {
type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
let mut subsets = vec![];
fn process_input(input: &str) -> Vec<Vec<char>> {
input
.trim_end()
.lines()
.map(|l| l.chars().collect())
.collect()
}
fn is_symbol(c: char) -> bool {
!c.is_alphanumeric() && c != '.'