Skip to content

Instantly share code, notes, and snippets.

@jkelleyrtp
jkelleyrtp / selection.rs
Created May 12, 2023 13:07
Revamped selection API
struct GlobalState {
name: String,
age: i32,
user: User,
}
struct User {
name: String,
age: i32,
config: Config,
@jkelleyrtp
jkelleyrtp / insane_polymorphism.rs
Last active July 12, 2022 19:23
Rust endpoint polymorphism
/*
This code shows how you would make a Rust API polymorphic over various functions.
It uses a technique to differentiate impls of a trait using a ZST marker.
This particular example might be too complex for the intended crate, hence its extraction into a gist.
*/
use std::marker::PhantomData;
use tokamak::{Request, Response};
fn main() {
use tokio::{runtime::Builder, sync::{mpsc}};
use winit::{event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::{Window, WindowBuilder}};
pub struct Gpu {
pub surface: wgpu::Surface,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
pub sc_desc: wgpu::SwapChainDescriptor,
pub swap_chain: wgpu::SwapChain,

Keybase proof

I hereby claim:

  • I am jkelleyrtp on github.
  • I am jkelleyrtp (https://keybase.io/jkelleyrtp) on keybase.
  • I have a public key ASC9lYFL_BAdEDf5sFtO1K9nRBh1ZVixwypItG7p7f8oIgo

To claim this, I am signing this object: