ext-rs 0.1.0

A Rust crate that brings C++-style extensions to Rust. Because why not?
Documentation
  • Coverage
  • 0%
    0 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 8.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 181.61 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • peeeuzin

ext-rs 🦀

Crates.io License Build Status

⚠️ DO NOT USE THIS IN PRODUCTION ⚠️

This is a joke crate. It's what happens when you doesn't have a job.

If you use this in production code, your pull request will be rejected, your colleagues will judge you, and rightfully so.


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 extract_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::BufReader;
use extract_rs::*;

let stdin = std::io::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, RIP Cloudflare

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