Skip to content

Instantly share code, notes, and snippets.

@KodrAus
KodrAus / maybe_initialized.rs
Created October 31, 2018 21:52
MaybeInitialized
union MaybeInitialized<T> {
initialized: T,
uninitialized: (),
}
@KodrAus
KodrAus / properties.rs
Last active June 11, 2018 07:51
Properties Macro
/*!
This example demonstrates a potential macro for capturing log properties.
The macro uses a syntax that's _similar_ to struct literals. The idea is to support
extensions to the way properties are captured using attributes.
There's a bit of a misalignment between how formatting is communicated in the log
message and the contextual properties, but they are a bit different. Args are slurped
up into the message using the formatting API whereas properties are exposed as data.
@KodrAus
KodrAus / NonRootScopeLifetime.cs
Created March 15, 2018 03:52
NonRootScopeLifetime
/*
An Autofac lifetime that ensures dependencies are only resolved from scoped containers.
This acts like a safety-net to prevent captive dependencies:
```
// Register some short-lived dependency using the `NonRootScopeLifetime`
var registration = builder.Register(c => c.Resolve<IStore>().BeginSession()).As<ISession>();
registration.RegistrationData.Lifetime = new NonRootScopeLifetime();
```
@KodrAus
KodrAus / dependable-dependencies.md
Created February 2, 2018 01:04
Dependable Dependencies

Dependable Dependencies

A dependable API, docs, examples and maintainership supported by tools and resources.

In this post I'd like to explore the quality libraries aspect of the [Rust 2018 roadmap RFC]. I'll lay out the framework that underpins my perspective on open source development as a starting point for conversation.

Quality means dependability. It also means a bunch of other things, but I'd like to focus on dependability here. The roadmap discusses sharpening Rust's offerings in a few focus domains, and I think a key to doing that is by supporting the dependability of libraries that fit within them.

What exactly is dependability though? I think a dependable library consists of:

@KodrAus
KodrAus / retrospective.md
Created January 13, 2018 23:50
A libz blitz retrospective

A libz blitz retrospective

The treacherous road to stabilisation is plagued by snakes and badgers. This picture has no relevence to the actual post.

This post is my personal retrospective of the libz blitz and my part in it. It's also a loose response to the [#Rust2018 call for blog posts] and a chance to show off my amazingly poor drawing skills. For the part most relevant to #Rust2018, see the last section.

For those who aren't familiar, the libz blitz was an initiative run by Rust's libs team in 2017 to address that year's roadmap goal of raising a solid core of the Rust crate ecosystem to a consistent level of completeness and quality. Specifically it aimed to improve the ecosystem maturity by evaluating and pushing a core set of crates to 1.0 stability. For more details, see [the original Rust Libz Blitz b

@KodrAus
KodrAus / Elasticsearch Aggregations.rs
Last active July 23, 2017 00:24
Elasticsearch Aggregations
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate serde_json;
extern crate serde;
pub mod aggs {
use std::slice::Iter;
use std::borrow::Cow;
use std::collections::BTreeMap;
use serde::{Deserialize, Deserializer};
use serde_json::{Value, Map};
@KodrAus
KodrAus / Updating .NET Core SDK used by VS.md
Created April 12, 2017 23:16
Updating .NET Core SDK used by VS

Updating .NET Core SDK used by VS

See: aspnet/Announcements#231

Visual Studio ships with its own version of the .NET Core SDK. You can point Visual Studio at a different version of the SDK by setting the MSBuildSdksPath environment variable to the appropriate location before launching Visual Studio. For example: %localappdata%\Microsoft\dotnet\sdk\2.0.0-preview1-005783\Sdks.

@KodrAus
KodrAus / main.rs
Last active March 19, 2017 03:28
Test deleting an mmapped file
extern crate memmap;
extern crate tempdir;
use std::path::PathBuf;
use std::fs::{File, remove_file};
use std::io::Write;
use std::str;
use tempdir::TempDir;
use memmap::{Mmap, Protection};
@KodrAus
KodrAus / main.rs
Last active March 16, 2017 00:33
New Request Body
pub struct Url<'a>(&'a str);
pub struct Body<R>(R);
type DefaultBody = &'static [u8];
impl<R> Body<R> {
pub fn new(inner: R) -> Self {
Body(inner)
}
@KodrAus
KodrAus / Debug Rust Binary Size.md
Last active March 2, 2017 21:11
Debug Rust Binary Size

Debug Rust binary size on Linux:

nm -S target/release/my-binary \
  | awk '{
           print $4 |& "rustfilt";
           "rustfilt" |& getline id;
           sub(/::h[0-9a-f]{16}$/, "", id);
           sums[id] += strtonum("0x"$2);
 counts[id] += 1