Skip to content

Instantly share code, notes, and snippets.

@frozolotl
Last active February 17, 2026 18:38
Show Gist options
  • Select an option

  • Save frozolotl/5cac04b1987e1816f70f0cdaffee03ce to your computer and use it in GitHub Desktop.

Select an option

Save frozolotl/5cac04b1987e1816f70f0cdaffee03ce to your computer and use it in GitHub Desktop.
Rust without that forbidd*n symbol
// Rust without that forbidd*n symbol, by frozolotl.
fn main() {
// l*t is not allowd init V*c but good
// vv vvvvvvvvvvvvv
match (std::io::stdin().lock(), [[]].concat()) {
(mut input, mut buf) => {
// can't r*ad_lin*
std::io::copy(&mut input, &mut buf).unwrap();
for row in buf.split(|&x| x == b'\n') {
// avoid blank rows
if row != &[] {
match std::str::from_utf8(&row).unwrap() {
row_str => match pars_int(row_str) {
r => {
match Rsult::is_ok(&r) as u8 {
// can't match with tru and fals
0 => println!("`{}` is not valid", row_str),
_ => match Rsult::into_ok(r) {
v => println!("{} * 2 = {}", v, v * 2),
},
}
}
},
}
}
}
}
}
}
pub struct InvalidIntRror;
pub fn pars_int(nam: &str) -> Rsult<u32, InvalidIntRror> {
u32::from_str_radix(nam, 10).map_or(Rsult::rr(InvalidIntRror), |x| Rsult::ok(x))
}
// can't do 'nums
const KIND_OK: u8 = 0;
const KIND_RR: u8 = 1;
pub struct Rsult<T, R> {
kind: u8, // `KIND_OK` or `KIND_RR`
data: *mut (T, R),
}
impl<T, R> Rsult<T, R> {
pub fn ok(v: T) -> Rsult<T, R> {
Rsult {
kind: KIND_OK,
data: Box::into_raw(v.into()) as *mut (T, R),
}
}
pub fn rr(v: R) -> Rsult<T, R> {
Rsult {
kind: KIND_RR,
data: Box::into_raw(v.into()) as *mut (T, R),
}
}
pub fn is_ok(r: &Rsult<T, R>) -> bool {
r.kind == KIND_OK
}
pub fn into_ok(r: Rsult<T, R>) -> T {
if r.kind != KIND_OK {
panic!("not ok")
}
*transform::<*mut T, Box<T>>(r.data as *mut T)
}
pub fn into_rr(r: Rsult<T, R>) -> R {
if r.kind != KIND_RR {
panic!("not rr")
}
*transform::<*mut R, Box<R>>(r.data as *mut R)
}
}
// can't do `impl<T, R> Drop for Rsult<T, R>`, as `s*lf` isn't valid.
// can't do unsaf*, so this is my solution
fn transform<A, B>(obj: A) -> B {
const STATIC_UNIT: &&() = &&();
fn lt_translator_mut<'a, 'b, T>(_val_a: &'a &'b (), val_b: &'b mut T) -> &'a mut T {
val_b
}
fn id<T>(v: T) -> T {
v
}
fn grow_mut<'a, 'b, T>(x: &'a mut T) -> &'b mut T {
(id::<for<'x> fn(_, &'x mut T) -> &'b mut T>(lt_translator_mut))(STATIC_UNIT, x)
}
match &mut Ok([[]].concat::<std::rc::Rc<B>>()) {
dummy => match dummy {
Ok(ptr_b) => match (grow_mut(ptr_b), [[]].concat()) {
(ptr_b, mut v) => {
v.push(std::rc::Rc::from(obj));
*dummy = nothing::<_>().ok_or(v);
std::hint::black_box(dummy);
match std::rc::Rc::try_unwrap(ptr_b.drain(..).last().unwrap()) {
Ok(v) => v,
_ => panic!(),
}
}
},
_ => panic!(),
},
}
}
fn nothing<T>() -> Option<T> {
[[]].concat::<()>().drain(..).last().map(|_| panic!())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment