Skip to content

Instantly share code, notes, and snippets.

View matthunz's full-sized avatar

Matt Hunzinger matthunz

View GitHub Profile
{
"program": "aztecs-bench",
"arguments": ["/home/matt/Documents/aztecs/dist-newstyle/build/x86_64-linux/ghc-9.10.1/aztecs-0.7.0/b/aztecs-bench/build/aztecs-bench/aztecs-bench", "iter", "exes"],
"rts_arguments": ["-pj"],
"end_time": "Mon Feb 24 17:13 2025",
"initial_capabilities": 0,
"total_time": 10.34,
"total_ticks": 10339,
"tick_interval": 1000,
"total_alloc":50298465544,
@matthunz
matthunz / flamegraph.svg
Last active February 24, 2025 22:09
flamegraph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matthunz
matthunz / blog.md
Last active December 8, 2024 13:27

UI and Declarative Programming in Rust

The graphical user interface (GUI) is the cornerstone of most modern applications. It is often the main interface to use a computer program, providing a bridge from your software to someone out there in the world. Therefore, to best represent our hard-earned application logic, a GUI should be responsive, robust, and accessible.

So let's use Rust, a modern language for efficient and robust software! Well...

Why are user interfaces so hard for Rust?

I've been working on open-source Rust projects for about 8 years now,

use std::{
cell::{RefCell, UnsafeCell},
mem,
ops::Deref,
};
fn main() {
let c = Component::new(app);
let mut scope = Scope::new(c);
scope.run();

Prerequisites

First install cargo-mobile2

cargo install cargo-mobile2

Then install and add the Android SDK and NDK for your platform to your path.

Setup

Start by creating a new crate and adding the required dependencies:

#[allow(non_snake_case)]
fn App() -> Element {
{
dioxus_core::internal::verify_component_called_as_component(App);
{
let mut data = use_signal(|| <[_]>::into_vec(
#[rustc_box]
::alloc::boxed::Box::new([
<[_]>::into_vec(
use dioxus::prelude::*;
use log::LevelFilter;
fn app(cx: Scope) -> Element {
render!(div {
onscroll: |_| todo!(),
width: "200px",
height: "200px",
overflow: "scroll",
@Composable
public static final void A(final int x, final int y, @Nullable Composer $composer, final int $changed) {
$composer = $composer.startRestartGroup(-1513727942);
ComposerKt.sourceInformation($composer, "C(A)32@866L4,33@875L4:MainActivity.kt#ptgicz");
int $dirty = $changed;
if (($changed & 14) == 0) {
$dirty = $changed | ($composer.changed(x) ? 4 : 2);
}
if (($changed & 112) == 0) {
use std::io::prelude::*;
use std::net::{TcpListener, TcpStream};
use std::thread;
fn main() {
let listener = TcpListener::bind("127.0.0.1:6667").unwrap();
for stream in listener.incoming() {
thread::spawn(move || {
handle_client(stream.unwrap());
full_url = fn ->
port = case @port do
80 ->
""
_ ->
":" <> Integer.to_string(@port)
end
"http://" <> conn.host <> port <> "/" <> short_url
end