Skip to content

Instantly share code, notes, and snippets.

View Aatch's full-sized avatar

James Miller Aatch

View GitHub Profile
import processing.pdf.*;
import java.util.Collection;
import java.util.Map;
float[] sizes;
float[] distortions;
float FREQUENCY = 5;
int mindiameter = 100;
@Aatch
Aatch / borrow-example.rs
Last active July 5, 2023 04:22 — forked from kolmodin/rust-json.rs
An example and explanation of how to use lifetimes and borrowing to avoid copying, while maintaining safety.
extern mod extra;
use extra::json::*;
/*
* This function manages to do absolutely no copying, which is pretty cool.
*
* "What are all those `'r`s?" you ask. Well, they're liftime parameters. They
* indicate how long something lasts (before it's freed). They can't change how
* long something lives for, they only allow you to tell the compiler stuff it
macro_rules! handle_element(
($tag:expr, $string:expr, $ctor:ident, [], $type_id:expr) => ( () );
($tag:expr, $string:expr, $ctor:ident, [ $($field:ident),* ], $type_id:expr, ) => (
if eq_slice($tag, $string) {
let _element = ~$ctor {
parent: Element::new($type_id, ($tag).to_str()),
$(
$field: None
),*
};