Sean Griffin

Co-lead of the team, full time Rust contributor. Creator of Diesel. Former Rails committer. they/them

Read this first

Neat Rust Tricks: Passing Rust Closures to C

One of Rust’s biggest selling points is how well it can interoperate with C. It’s able to call into C libraries and produce APIs that C can call into with very little fuss. However, when dealing with sufficiently complex APIs, mismatches between language concepts can become a problem. In this post we’re going to look at how to handle callback functions when working with C from Rust.

Our hypothetical library has a Widget struct, which periodically generates events. We want to take a callback function from users that is called whenever one of these events occurs. More concretely, we want to provide this signature:

impl Widget {
    fn register_callback(&mut self, callback: impl FnMut(Event)) {
        // ...

Unlike Rust, C has no concept of closures. Instead it has function pointers. To put this in Rust terms, you can take fn(Event), but not impl FnMut(Event). Function pointers...

Continue reading →

Thoughts on Arbitrary Pagination

Pagination is the act of breaking a data set into multiple pages to limit the amount of data that has to be processed and sent by a server at once. We’re going to be changing how pagination works on, and I wanted to share some musings about the issues with supporting this as a generic abstraction. While I’m going to be talking about some PostgreSQL internals in this article, the general ideas presented apply to any SQL database.

“Simple” Pagination

The most common form of pagination uses page numbers. This is done by having numbered page links shown towards the bottom of the UI, and including ?page=5 in the URL. Often there are also links for next page, previous page, first page, and last page. The UI might look like this.

Screen Shot 2019-08-20 at 10.02.27 AM.png

This form of pagination is implemented on the server by adding an offset to the query. The total is also needed to know how many pages there actually...

Continue reading →

Moving on from Rails and what’s next

It’s been more than 6 years since my first commit to Ruby on Rails. I had just gotten my first full time Ruby position, was excited to move away from PHP, and wanted to give back. Since then I made 1452 commits to the project. Today, I am finally ready to move on from Rails.

In 2014 I started working on the Active Record Attributes API. We got to a working implementation fairly quickly, but it took many more months and thousands of lines of code to get to an implementation that I was comfortable shipping. By the time Rails 4.2 came out, I had ended up rewriting a significant portion of the library, which meant I was spending more and more of my time maintaining that code and fixing other issues.

Around the time that 4.2 was entering beta, I decided it was time to try and take this commitment full time. I spent the next 4 years devoting as much of my professional time as possible to the...

Continue reading →