A quick intro to Rust 🦀 for C# devs

Tim Abell
Contract C# Tech Lead
Host of Reading Rust Meetup
0x5.uk

// hello.rs
fn main() {
    println!("Hello dotnet oxford!");
}

Dotnet Oxford Lightning talks 17 June 2025

The hunt for the perfect language

C# 💼 💷
Ruby on Rails (GDS)
GoLang (Schema Explorer)
Rust! (gitopolis)

Tim Abell | 0x5.uk

Popularity

Most Admired 2024

Tim Abell | 0x5.uk

Similarities to C#

Tim Abell | 0x5.uk
  • Compiled
  • Strong typed
  • Memory safe
  • Multi-paradigm, broad applicability
  • Cargo Crate == NuGet Package
  • unsafe escape hatch
  • Not quite Haskell-level functional (no higher-kinded types)
Tim Abell | 0x5.uk

Type inference

var == let

let url = &repo.remotes["origin"].url; // url is a &String
Tim Abell | 0x5.uk

LINQ-like chaining of list processing

repos
  .into_vec()
  .into_iter()
  .filter(|r| r.tags.contains(&tag.to_string()))
  .collect()
Tim Abell | 0x5.uk

async

pub(crate) async fn trace_requests(req: Request<Body>, next: Next)
	-> Result<Response, StatusCode>
{
	...
	let response = next.run(req).await;
	...
}

Needs runtime, e.g. Tokio

Tim Abell | 0x5.uk

Differences from C#

Tim Abell | 0x5.uk

discord.com/blog/why-discord-is-switching-from-go-to-rust

Tim Abell | 0x5.uk
  • No IL, No GC, No Runtime
  • Faster and less overhead
  • No nulls - Option<>
  • No exceptions - panic! or Result<>
  • Immutable by default mut
  • Borrowing & lifetimes (later slides)
  • Return of last expression
Tim Abell | 0x5.uk

Slightly different function signature

pub fn add(&mut self, repo_folder: String) -> Result<(), GitopolisError> {
Tim Abell | 0x5.uk

Richer enum type

enum Commands {
	Add {
		repo_folders: Vec<String>,
	},
	List {
		tag: Option<String>,
		long: bool,
	},
}
Tim Abell | 0x5.uk

Macros are everywhere

#[derive(Subcommand)]
enum Commands {
...
println!("🏢 {}> Repo folder missing, skipped.", &repo.path);
Tim Abell | 0x5.uk

Matching, Option and Result

match &Args::parse_from(wild::args()).command {
	Some(Commands::Add { repo_folders }) => add(repo_folders.to_owned()),
	Some(Commands::Remove { repo_folders }) => {
		init_gitopolis().remove(repo_folders).expect("oops");
	}
	Some(Commands::List { tag: tag_name, long,
	}) => list(
		init_gitopolis().list(tag_name).expect("oops"), *long,
	),
	None => {
		panic!("oh bugger")
	}
}
Tim Abell | 0x5.uk

Memory management

Ownership, borrowing & lifetimes vs. garbage collection

Rust: RAII - Resource Acquisition is Initialization

  • construction - memory-allocated (malloc)
  • destruction (goes out of scope) - release/free/de-allocate
  • single owner of every resource - borrow with &something
fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) {
Tim Abell | 0x5.uk

Ecosystem & tooling

  • cargo
  • rustup / asdf-vm
  • crates.io - like nuget.org
  • clippy - linter cargo clippy --fix
  • cargo format
  • VSCode, RustRover, Windsurf, NeoVim
  • Language-server
Tim Abell | 0x5.uk

Testing

#[test]
fn tags() {
	// Arrange
	let gitopolis = Gitopolis::new(storage, git);
	// Act
	let result = gitopolis.tags().expect("oh no!");
	// Assert
	assert_eq!(3, result.len());
	assert_eq!("another_tag", result[0]);
}
Tim Abell | 0x5.uk

Error handling & propogation

  • Explicit
  • panic! or return Result<>
  • Cleaner than GoLang
  • More predictable than C# Exceptions
  • Ergonomic
Tim Abell | 0x5.uk

Compilation

  • No IL
  • Longer compile, but shift-left on problems
  • Static deploy-anywhere binaries
  • glibc linking / musl
Tim Abell | 0x5.uk

Rust vs C/C++

  • Memory safe by default (security!!)
  • Easier to learn
  • Can be embedded in C programs
  • US Gov mandate
  • Enterprise conversions happening now (Microsoft, Google Android, etc)
Tim Abell | 0x5.uk

Applications

  • Web / microservice
  • Backend (axum etc)
  • Frontend (leptos etc)
  • WASM / WASI - serverless - fast startup
  • Mobile apps
  • Embedded systems
  • Crypto
Tim Abell | 0x5.uk

Culture & community

Tim Abell | 0x5.uk

A look at some code

If there's time...

https://github.com/rustworkshop/gitopolis

Tim Abell | 0x5.uk

Tim Abell

fn main() {
    println!("Thanks!");
}
Tim Abell | 0x5.uk

who am i

my journey to rust

> "Rust continues to be the most-admired programming language with an 83% score this year." > ~ Stackoverflow developer survey 2024 I chose for cheap web-scale

- like OneOf or LanguageExt, but baked-in

- tidy default unit test options - many crates for improved testing - strong support for profiling

Next slide!

Q&A