Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
@stevedonovan
stevedonovan / shared.rs
Created April 14, 2017 13:49
An ergonomic way of saying Rc<RefCell>
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
#[derive(Clone)]
struct Shared<T> {
v: Rc<RefCell<T>>
}
@stevedonovan
stevedonovan / runner-article.md
Last active December 15, 2017 10:34
Temporary staging area for article

Cargo Manages Crates

Cargo is an important feature of the Rust ecosystem, using a central repository of versioned packages and ensuring reproducible builds. It has learned important lessons from more ad-hoc solutions like Go's 'go get' and is miles ahead from what is available for C++; it is like Maven, except TOML is easier to write and read than XML.

So suggesting that it is not ideal for some situations may come across as being perverse. I've seen people

@stevedonovan
stevedonovan / closures.md
Last active May 19, 2018 10:53
Rust Closures Article

Why Rust Closures are (Somewhat) Hard

The Easy Case: Lua

Since hard is always relative to something else, I'd like to start with a dynamic language. Functions in Lua are essentially anonymous and can capture variables from their environment (pretty much like with JavaScript, which Lua resembles in several important ways):

@stevedonovan
stevedonovan / common-rust-traits.md
Created July 1, 2018 12:38
The Common Rust Traits

What is a Trait?

In Rust, types containing data - structs, enums and any other 'aggregate' types like tuples and arrays - are dumb. They may have methods but that is just a convenience; they are just functions. Types have no relationship with each other.

Traits are the abstract mechanism for adding functionality to types and establishing relationships between them.

@stevedonovan
stevedonovan / el.lua
Created October 2, 2021 15:38
el is a Lua expression evaluator with shell-friendly shortcuts, like ^string and print[[]
#!/usr/bin/lua
-- Flatten ALL those tidy tables and add environment lookup
local tables = {math,io,os,string,bit32}
setmetatable(_G,{
__index = function(t,key)
for _,m in ipairs(tables) do
local v = m[key]
if v ~= nil then return v end
end
return os.getenv(key)