A ScyllaDB Community
Rust: A Productive Language for
Writing Database Applications
Carl Lerche
Principal Engineer at AWS
RUST IS (MOSTLY) USED AT THE
INFRASTRUCTURE LEVEL
RUST IS PRODUCTIVE
SAME BENEFITS APPLY
HIGHER UP THE STACK
ARE WE WEB YET?
HTTPS://AREWEWEBYET.ORG
TOASTY
A NEW ORM FOR RUST
EASE OF USE
OVER
MAXIMIZING PERFORMANCE
SQL
BUT ALSO NOSQL
PROCEDURAL MACROS
async fn hello_world() -> impl IntoResponse {
let hello_world = json!({
"hello": "world"
});
Json(hello_world)
}
let app = Router::new()
.route("/", get(hello_world));
#[derive(Serialize)]
struct HelloWorld {
hello: &'static str,
}
async fn hello_world() -> impl IntoResponse {
Json(HelloWorld {
hello: "world",
})
}
#[toasty::model]
struct User {
#[key]
#[auto]
id: Id,
#[unique]
email: String,
todos: [Todo],
}
SCHEMA FILE
AND
CODE GENERATION
let user = User::find_by_email(email)
.get(&db)
.await?;
async fn hello_world() -> impl IntoResponse {
let message = "world";
let hello_world = json!({
"hello": message
});
Json(hello_world)
}
HOW IMPORTANT IS READING
THE GENERATED CODE?
#[derive(Serialize)]
struct HelloWorld {
hello: &'static str,
}
AVOID SECOND-ORDER
TRAIT BOUNDS
fn set_name<T>(&mut self, name: T)
where
T: Into<String>,
{ ... }
fn serve<T, R>(T)
where
T: Service<Response = R>
R: Into<http::Response>,
{ ... }
pub fn find_by_email<'a>(
email: impl stmt::IntoExpr<'a, String>
) -> FindByEmail<'a> {
let expr = User::EMAIL.eq(email);
let query = Query::from_expr(expr);
FindByEmail { query }
}
RESULT FOR RUNTIME ERRORS
PANIC FOR BUGS
uri::Builder::new()
.authority("tokio.rs")
.build()
.unwrap();
let Ok(uri) = uri::Builder::new()
.authority(user_provided_authority)
.try_build()
else {
eprintln!("invalid authority");
abort();
};
let user = User::find_by_email(email)
.get(&db)
.await?;
for todo in user.todos() {
println!(
"Category: {}",
todo.category().name);
}
let user = User::find_by_email(email)
.include(toasty::path![User.todos.category])
.get(&db)
.await?;
WHAT IS NEXT?
THANK YOU
HTTPS://DISCORD.GG/TOKIO

Rust: A Productive Language for Writing Database Applications