Safety Goggles for Alchemists

The Path Towards Safer Transmute

Since Rust’s inception, mem::transmute has been the poster-dragon of unsafe code, but its reign of error is coming to an end! In this talk blog post, you’ll learn how Rust is poised to become the first systems programming language with transmutation safety, and how safe transmute is already being put to use to build next-gen systems.

repr(C): Clear, Simple and (Sometimes) Wrong

Too often, repr(C) is thought of as a panacea to layout stability and portability problems; that values of a type marked repr(C) can be consistently reflected upon, across different platforms, different compiler versions, and even perhaps different minor library versions. That is not always the case!

Announcing scoped-trace.

Today, I’m announcing scoped-trace, a crate for capturing scoped, tree-like execution traces.

Here are the crate’s important links:

Oh the Crates You’ll Go! A 2022 Retrospective

As my first full calendar year in the Rust Platform Team at AWS draws to a close, I thought it might be illuminating to reflect on what I worked on. The breadth of crates I released or contributed to surprised me! Time really does fly when you’re having fun.

Native Reflection in Rust

Today, I’m releasing deflect, an implementation of reflection for Rust. Deflect can be used to recover the concrete types of trait objects, inspect the internal state of async generators, pretty-print arbitrary data, and much more.

Typesetting a Resume with HTML and CSS

With my PhD drawing to a close, I’m on the job market! I’ll need a slick resume ASAP, but how to typeset it?

Microsoft Word?
...don't have it.
LaTeX?
...don't have the patience for it.
HTML + CSS?
...now that could work!

Rust’s SemVer Snares: repr(transparent) Super-Cut

(Part of an ongoing series!)

In the last two posts, repr(transparent) provided an unusual mechanism by which safe, downstream code could inadvertently rely on the size and alignment of an upstream type. In this post, I’ll recap the issue and discuss why it is tricky to fix.

Rust’s SemVer Snares: Alignment

(Part of an ongoing series!)

In Rust, changes to a type’s alignment are not usually understood to be Breaking Changes™. Of course, that isn’t to say you can’t break safe, downstream code by changing the alignment of a type…

Rust’s SemVer Snares: Sizedness and Size

(Part of an ongoing series!)

In Rust, changes to a type’s size are not usually understood to be Breaking Changes™. Of course, that isn’t to say you can’t break safe downstream code by changing the size of a type…

Rust’s SemVer Snares: Introduction

At the heart of Semantic Versioning is a distinction between incompatible API changes (“breaking” changes) and backwards-compatible API changes (“non-breaking” changes). When you make a change that could break existing code, you must increment the MAJOR component of its version number. Since failing to do this correctly may cause builds or tests to fail seemingly-spontaneously, knowing what kinds of changes are breaking and which are not is crucial to good crate hygiene.

How does Brown University know where you are?

In September 2020, Brown University accused students of lying about their location; e.g.:

The University has learned that between September 14, 2020 and September 21, 2020 you were allegedly in the Providence area during which time your location of study was listed as remote. This alleged behavior is a violation of the Student Code of Conduct and the COVID-19 Campus Safety Policy. A copy of the Student Commitment to COVID-19 Community Health and Safety Requirements is attached for your review, along with this link to the COVID-19 Campus Safety Policy. failure to abide by these requirements is a violation of the Code of Student Conduct. 
Based on the details of the incident and your student conduct history, the Office of Student Conduct & Community Standards has decided to allow you the opportunity to accept responsibility for the following prohibited conduct without having a COVID-19 Dean's Review Meeting:
• D.8 Failure to Comply
• D.13 Misrepresentation

What was Brown’s basis for these accusations?

Brown’s Most Expensive Books

  • What’s the most expensive required textbook at Brown?
  • What’s the most expensive class?
  • What’s the most expensive department?

How Many First-Years Are Taking Their Free Course?

To de-densify campus, Brown University moved to a three-term model in which students take courses for two of three possible terms. This third term will be carved out of the summer months of 2021, during which an unlucky subset of the student body will swiftly discover that Brown does not air-condition its dorms. So, who are these unenviable souls? Well, first-years, obviously, who will begin in the spring semester and continue through the summer.

To compensate them for this inconvenience, Brown has extended all first-years the opportunity to remotely take one course this Fall, for free! How many took Brown up on this offer?

Brown’s Class Size Paradox

University Admissions departments love to brag about their schools’ small class sizes. Brown University, for instance, boasts a 7:1 student–faculty ratio (so “you’ll have a lot of face-to-face time with some of the best researchers and teachers in academia”) and that “72 percent of our undergraduate classes have fewer than 20 students.” These claims invite prospective students to daydream of cozy, intimate classrooms, and personalized learning experiences — dreams quashed (or perhaps squished?) on one’s first day of classes.

Nobody is lying, per se — this is merely an instance of the “class size paradox”: the size of the average class is relatively small, but the experience of the average student suggests otherwise.

Scoped Trait Implementations

In Rust, the impl keyword doesn’t have an associated visibility; there’s no such thing as pub impl. However, that isn’t to say that implementations don’t have visibility—they do! Enter: RFC2145 - Type Privacy.

Private Methods on a Public Trait

In Rust, the methods of a trait inherit the visibility of the trait itself:

pub trait Foo<Arg> {

    pub(self) fn foo(&self, arg: Arg);

    /* other public methods */

}
error[E0449]: unnecessary visibility qualifier
 --> src/lib.rs:7:3
  |
7 |   pub(self) fn foo(&self, arg: Arg);
  |   ^^^^^^^^^

At minimum, we should hide this method from our documentation:

pub trait Foo<Arg> {

    #[doc(hidden)]
    fn foo(&self, arg: Arg);

    /* other public methods */

}

…but this doesn’t actually prevent outsiders from calling our method! Fortunately, there are at least three other patterns #[doc(hidden)] can be combined with to make foo externally unusable.

Taming nalgebra’s Rustdoc

Nalgebra is a powerhouse of functionality, but its documentation can be overwhelming—the documentation for Matrix lists over 600 methods. Your documentation endeavors might not be quite so overwhelming, but you still could benefit from these three tricks nalgebra uses to improve its docs.

Fixing include_bytes!

Rust’s include_bytes! macro lets you statically include the contents of a file into your executable’s binary. The builtin is a quick-and-dirty solution for packaging data with your executable, and perhaps even helping the compiler optimize your code! Unfortunately, it’s difficult to use correctly.

Javascript Generators, Meet XPath

Using Generators to Modernize a Geriatric Javascript API for $CURRENT_YEAR