# Porting the C# clippy app to Rust

Published: 2023-04-23
Last updated: 2023-04-28

Last week, I [wrote a little hello world app](/blog/containerizing-a-csharp-hello-world-app/) that responds to HTTP requests with a clippy ASCII art. But the docker image for the app was 111MB in size.

So today, I decided to port the app to rust.

*If you only want to see the code, [here you go](https://github.com/gldraphael/clippy). [Here's the PR](https://github.com/gldraphael/clippy/pull/4).*

It took me 3 hours to port the app, whereas writing the C# app had barely taken me 5 minutes. I ended up spending most of the time trying to decide which web-framework to use, and the rest of the time trying to put together a `Dockerfile`.

The rust code in itself was straightforward. I chose to use a web-framework called [`axum`](https://github.com/tokio-rs/axum), and they already have a [huge list of examples](https://github.com/tokio-rs/axum/tree/v0.6.x/examples) in their GitHub repository.

Here's my rust code:

```rust
use axum::{response::Result, Router};
use std::net::SocketAddr;
use std::env;

const CLIPPY:&str = r#"

         __
        /  \        _____________
        |  |       /             \
        @  @       | It looks    |
        || ||      | like you    |
        || ||    Result {
    Ok(CLIPPY)
}

fn get_port() -> u16 {
    env::var(PORT_ENV_VAR)
        .unwrap_or("NOT_SET".to_string())
        .parse::()
        .unwrap_or(3000)
}
```

It's not very different from C# if you think about it.
It's almost as if C++ and C# had a baby.

Since the goal of the rewrite was to reduce the docker image size, here are some size stats:
Final ImageLanguageSize`ubuntu:lunar`C#160MB`ubuntu/dotnet-deps:7.0_edge`C#111MB`alpine:latest`Rust13.1MB`scratch`Rust6MB
Mission accomplished.

