Skip to content

Instantly share code, notes, and snippets.

@3DRaven
3DRaven / delegate.md
Last active April 19, 2025 13:42
Type-safe delegation over generics in Rust without the newtype pattern
pub struct GenericId<T>(pub i64, pub PhantomData<T>);

pub struct PhantomMyId;
pub type MyId = GenericId<PhantomMyId>;
pub struct PhantomOtherId;
pub type OtherId = GenericId<PhantomOtherId>;


pub fn foo(my_id: &amp;MyId){
@3DRaven
3DRaven / example.java
Last active March 9, 2023 13:24
Java Builder with compile time checking of full initialization (Strict Builder pattern)
public class Person {
private final String username;
private final int age;
Person(PersonBuilder personBuilder) {
this.username = personBuilder.username;
this.age = personBuilder.age;
}