Skip to content

peeeuzin/ext-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ext-rs 🦀

Crates.io License Build Status

⚠️ USE THIS IN PRODUCTION!! ⚠️

If you want to experience the thrill of living on the edge, go ahead and use this crate in your production code. Your pull requests will be celebrated, your colleagues will admire your daring spirit. Sincerely, I don't know what could possibly go wrong if you put this in production.


The Problem That Doesn't Exist

You know what Rust is really missing? The C++ stream extraction operator (>>). Sure, Rust has:

  • Proper error handling
  • Zero-cost abstractions
  • Memory safety
  • Read traits with explicit error types
  • parse() methods that don't panic
  • Actually readable code

But where's the fun in that? Where's the mysterious operator overloading? Where's the silent panic when parsing fails? Where's the chaos?

The "Solution"

This crate brings the "magic" ✨ of C++'s std::cin >> value to Rust by abusing the right-shift operator because, apparently, that's what we're doing with our lives now.

Installation

[dependencies]
ext-rs = "0.1.0"

Usage

use std::io::BufReader;
use ext_rs::*;

let data = b"42 Hello 3.14";
let mut reader = ExtReader(BufReader::new(&data[..]));

let mut int_value: i32 = 0;
let mut string_value = String::new();
let mut float_value: f64 = 0.0;

// The cursed syntax:
reader >> &mut int_value >> &mut string_value >> &mut float_value;

// Or if you prefer your bad decisions to be more explicit:
reader.extract(&mut int_value)
      .extract(&mut string_value)
      .extract(&mut float_value);

assert_eq!(int_value, 42);
assert_eq!(string_value, "Hello");
assert_eq!(float_value, 3.14);

If you want to parse stdin directly:

use std::io::{stdin, BufReader};
use ext_rs::*;

let stdin = stdin();
let mut reader = ExtReader(BufReader::new(stdin.lock()));

let mut int_value: i32 = 0;
reader >> &mut int_value;

// Curiously, the linter mark this as unused, but, who cares?

Features

  • No error handling: Because who needs that? Unwrap all the things!
  • Operator abuse: Who cares about Rust's design principles?
  • Bad performance: Efficiency is overrated
  • Unwrap everywhere: Because .unwrap() never caused any problems, Cloudflare doesn't know how to code though.

Why This Exists

Because.

FAQ

Q: Should I use this?
A: No.

Q: But what if—
A: No.

Q: Can I contribute?
A: I mean, technically yes, but also... why?

Q: Does this follow Rust best practices?
A: It follows the best practice of showing you what NOT to do.

Comparison with Proper Rust Code

This crate:

reader >> &mut value; // What could go wrong? 🔥

Actual Rust:

let value: i32 = line
    .trim()
    .parse()
    .expect("Please enter a valid number");

One of these is maintainable.

What You Should Actually Use

License

MIT (because even jokes deserve proper licensing)

Disclaimer

This crate is meant for educational purposes only—specifically, to educate you on what not to do. If you find yourself actually wanting to use this, please take a step back, have a cup of coffee, and reconsider your life choices.

Remember: Just because you can doesn't mean you should.


Made with ❤️ and poor judgment

Releases

No releases published

Packages

No packages published

Languages