#rustlang
Explore tagged Tumblr posts
as-if-and-only-if · 4 months ago
Text
Rust’s never type is wild to me.
So, if you’re not familiar with type theory, the empty type, which we’ll denote ∅ here (which Rust calls never, but more on that later) is the type with no elements.
But…how do you actually say that the type “has no elements” within the type theory?
You can’t say something like ¬∃x, x : ∅, in part because inside most type theories, this statement doesn’t even make sense: we need to know the type of x when bound, and more importantly, typing judgments like x : ∅ are not statements you can make within the theory itself.
Actually, you often don’t even want to use ¬ at all: we want to define ¬P in terms of ∅ as P → ∅ ! This is because having an element of the empty type would (if all goes well) be a contradiction, so if you can construct such a contradiction out of P (i.e. ->), then P must be false. ∅ is near the foundations, so we don’t have much to work with when setting up its meaning.
What we can do is encode the principle of explosion, i.e. that given an element of the empty type (a contradiction!) we can derive anything.
That is, we have an axiom explode : ∀(A : Type), ∅ → A. For any type A, give me an element x of ∅, and I will hand you an element of that type (namely explode A x : A).
(If you’re familiar, ignore universe polymorphism/Type vs. Prop and the fact that A isn’t a type family.)
This is what makes the empty type the empty type. If we didn’t include this axiom, the empty type would have no real emptiness behavior besides “gee, I can’t quite figure out how to make an element of this type”. You wouldn’t know it’s empty, since there would be no consequences to finding out that something has type ∅.
(Aside: this axiom fits into a very general pattern of what it means to define a type inductively, and lets us do “induction on the empty type”. It’s not ad-hoc!)
———
So it should be clear that if you ever do find an element of ∅, your theory is inconsistent, as you can prove anything you want.
Which is why Rust’s empty type, called never, is pretty neat. To me, someone who does not know Rust, and who literally opened the docs as soon as I installed them, scrolled down, and said “ooh, what’s never?”
See, Rust expressions can have type never. (I’m calling them expressions; I don’t know if this is what rustaceans call them)
But, how?! Surely that breaks everything! Well…yes. Which is why the only way to maintain consistency is to have these expressions break everything.
Let me explain: the things with type never never return a value (hence the name). They diverge: they’re things like exit or break or infinite loops.
And thanks to the explode axiom, these expressions can be coerced to any type. For example, you can say x: u32 = { exit() }, and Rust will say “makes sense to me”. (Apologies for any bad Rust syntax.)
This is—surprisingly!—fine.
exit() : never, just like any element of the empty type, really is a contradiction in the type system, but being able to write it in Rust code doesn’t actually make the type system inconsistent—since we leave the type system as soon as it’s encountered. (Or, in the case of an infinite loop, we never manage to actually finish constructing a value of never.)
So, while the syntax of Rust can contain “contradictions”, they never get the chance to behave as contradictions in the model of Rust’s type system formed by the values it constructs at runtime. I.e. running a real program never invalidates the type system. We’re saved from the runtime nonsense that would be created by explode A x by having the system actually explode instead.
There’s something to be said for this, but it is weird. Saying “x : u32” in Rust is apparently scoped in a certain way: it says “as long as the value we call x exists, it has type u32.” It doesn’t guarantee the existence of something with type u32.
This means that you don’t actually have to break the whole type system to use never; you just have to break the context in which x exists. E.g., if you’re inside a function, then let x: bool { return 500 }, where the return returns to the outer function, is fine. x never finishes being constructed, so the guarantee provided by its type annotation is (vacuously) satisfied.
I wonder if this is linked to the notion of lifetimes in Rust, and how that’s reflected in the theory behind the type system. And I’m not a type theorist (or someone who knows Rust), but I am also curious how type theorists talk about diverging terms; in Lean, for example, a top-level term of type Empty is verboten. You create diverging terms by using the partial keyword, and then you’re prohibited from proving anything about their behavior (but they still have types as usual).
This isn’t the first time people have talked about this, by far, I’m sure; happy to hear any takes (or corrections). Much to learn! :)
110 notes · View notes
forever-stuck-on-java-8 · 4 months ago
Text
shout out to @fish-shell for completing their port to @rust-official
78 notes · View notes
itsjunetime · 11 months ago
Text
I made a little terminal-based PDF viewer! For fun, mostly, 'cause I thought it would be a fun challenge, but also a PDF viewer is the only other windowed program I currently use on my computer besides my browser and my terminal, so I thought it would be fun to replace.
It could still be more performant and handle its multi-threading stuff better (and I do have some ideas to do that), but I thought people here might get a kick out of this. It's built in rust, using ratatui, etc, you know the deal.
If you want to check it out, the code's here: https://github.com/itsjunetime/tdf
123 notes · View notes
daniel-nerd · 2 years ago
Text
got myself some thigh high socks that means my code will compile now! right?
Tumblr media
170 notes · View notes
quietmarie · 4 months ago
Text
Tumblr media
bwaaaa I'm doing programming crimes again
(this is from a small project that is heavily inspired by axum, but don't worry it won't go anywhere I realised there are better approaches)
10 notes · View notes
zephiris · 2 years ago
Text
Java is a trash language that should burn in the parts of hell where hitler is
Rust on the other hand is a bratty lil language that should burn in the parts of hell where queers party
139 notes · View notes
somerandev · 6 months ago
Text
🫚 Day 35 of Game Dev for 🫱Teleport Man🫲
When the right hand is occupied, the left one punches instead of using the teleport ability.
Tried making the punch push objects... but...... i t h i n k i m e s s e d s o m e t h i n g u p
12 notes · View notes
this-week-in-rust · 7 days ago
Text
This Week in Rust 595
Hello and welcome to another issue of This Week in Rust! Rust is a programming language empowering everyone to build reliable and efficient software. This is a weekly summary of its progress and community. Want something mentioned? Tag us at @thisweekinrust.bsky.social on Bluesky or @ThisWeekinRust on mastodon.social, or send us a pull request. Want to get involved? We love contributions.
This Week in Rust is openly developed on GitHub and archives can be viewed at this-week-in-rust.org. If you find any errors in this week's issue, please submit a PR.
Want TWIR in your inbox? Subscribe here.
Updates from Rust Community
Official
March Project Goals Update
Newsletters
The Embedded Rustacean Issue #43
Project/Tooling Updates
Shadertoys ported to Rust GPU
Meilisearch 1.14 - composite embedders, embedding cache, granular filterable attributes, and batch document retrieval by ID
rust-query 0.4: structural types and other new features
Observations/Thoughts
Rebuilding Prime Video UI with Rust and WebAssembly
ALP Rust is faster than C++
what if the poison were rust?
A surprising enum size optimization in the Rust compiler
Two Years of Rust
An ECS lite architecture
A 2025 Survey of Rust GUI Libraries
BTrees, Inverted Indices, and a Model for Full Text Search
Cutting Down Rust Compile Times From 30 to 2 Minutes With One Thousand Crates
SIMD in zlib-rs (part 1): Autovectorization and target features
Avoiding memory fragmentation in Rust with jemalloc
[video] Bevy Basics: Who Observes the Observer
Rust Walkthroughs
Rust Type System Deep Dive From GATs to Type Erasure
Async from scratch 1: What's in a Future, anyway? | natkr's ramblings
Async from scratch 2: Wake me maybe | natkr's ramblings
Building a search engine from scratch, in Rust: part 4
Pretty State Machine Patterns in Rust
[video] Build with Naz : Declarative macros in Rust
Miscellaneous
March 2025 Jobs Report
Rust resources
Crate of the Week
This week's crate is wgpu, a cross-platform graphics and compute library based on WebGPU.
Despite a lack of suggestions, llogiq is pleased with his choice.
Please submit your suggestions and votes for next week!
Calls for Testing
An important step for RFC implementation is for people to experiment with the implementation and give feedback, especially before stabilization.
If you are a feature implementer and would like your RFC to appear in this list, add a call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
No calls for testing were issued this week by Rust, Rust language RFCs or Rustup.*
Let us know if you would like your feature to be tracked as a part of this list.
RFCs
Rust
Rustup
If you are a feature implementer and would like your RFC to appear on the above list, add the new call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
Call for Participation; projects and speakers
CFP - Projects
Always wanted to contribute to open-source projects but did not know where to start? Every week we highlight some tasks from the Rust community for you to pick and get started!
Some of these tasks may also have mentors available, visit the task page for more information.
rama - add serve command to rama-cli
rama - add support for include_dir for to ServeDir and related
rama - add curl module to rama-http-types
If you are a Rust project owner and are looking for contributors, please submit tasks here or through a PR to TWiR or by reaching out on X (formerly Twitter) or Mastodon!
CFP - Events
Are you a new or experienced speaker looking for a place to share something cool? This section highlights events that are being planned and are accepting submissions to join their event as a speaker.
If you are an event organizer hoping to expand the reach of your event, please submit a link to the website through a PR to TWiR or by reaching out on X (formerly Twitter) or Mastodon!
Updates from the Rust Project
480 pull requests were merged in the last week
Compiler
detect and provide suggestion for &raw EXPR
don't suggest the use of impl Trait in closure parameter
make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path
tell LLVM about impossible niche tags
remove Nonterminal and TokenKind::Interpolated
re-use Sized fast-path
Library
add core::intrinsics::simd::{simd_extract_dyn, simd_insert_dyn}
initial UnsafePinned implementation (Part 1: Libs)
polymorphize array::IntoIter's iterator impl
speed up String::push and String::insert
std: add Output::exit_ok
Cargo
added symlink resolution for workspace-path-hash
improved error message when build-dir template var is invalid
Rustdoc
search: add unbox flag to Result aliases
enable Markdown extensions when looking for doctests
Clippy
arbitrary_source_item_ordering should ignore test modules
implicit_return: better handling of asynchronous code
accept self.cmp(other).into() as canonical PartialOrd impl
add manual_abs_diff lint
consecutive returns dont decrease cognitive Complexity level anymore
consider nested lifetimes in mut_from_ref
correctly handle bracketed type in default_constructed_unit_struct
deprecate match_on_vec_items lint
do not propose to auto-derive Clone in presence of unsafe fields
fix: iter_cloned_collect false positive with custom From/IntoIterator impl
fix: map_entry: don't emit lint before checks have been performed
fix: redundant_clone false positive in overlapping lifetime
various fixes for manual_is_power_of_two
Rust-Analyzer
ast: return correct types for make::expr_* methods
add children modules feature
add normalizeDriveLetter
distribute x64 and aarch64 Linux builds with PGO optimizations
fix dyn compatibility code bypassing callable_item_signature query
fix a small bug with catastrophic effects
fix an incorrect ExpressionStore that was passed
prevent panics when there is a cyclic dependency between closures
shadow type by module
ignore errors from rustfmt which may trigger error notification
port closure inference from rustc
Rust Compiler Performance Triage
Relatively small changes this week, nothing terribly impactful (positive or negative).
Triage done by @simulacrum. Revision range: e643f59f..15f58c46
1 Regressions, 3 Improvements, 3 Mixed; 2 of them in rollups 35 artifact comparisons made in total
Full report here
Approved RFCs
Changes to Rust follow the Rust RFC (request for comments) process. These are the RFCs that were approved for implementation this week:
No RFCs were approved this week.
Final Comment Period
Every week, the team announces the 'final comment period' for RFCs and key PRs which are reaching a decision. Express your opinions now.
Tracking Issues & PRs
Rust
Split elided_lifetime_in_paths into tied and untied
check types of const param defaults
Stabilize flags for doctest cross compilation
Do not remove trivial SwitchInt in analysis MIR
Implement a lint for implicit autoref of raw pointer dereference - take 2
Implement Default for raw pointers
make abi_unsupported_vector_types a hard error
Stabilize let chains in the 2024 edition
Make closure capturing have consistent and correct behaviour around patterns
Stabilize the cell_update feature
Other Areas
*No Items entered Final Comment Period this week for Rust RFCs, Cargo, Language Team, Language Reference or Unsafe Code Guidelines.
Let us know if you would like your PRs, Tracking Issues or RFCs to be tracked as a part of this list.
New and Updated RFCs
No New or Updated RFCs were created this week.
Upcoming Events
Rusty Events between 2025-04-16 - 2025-05-14 🦀
Virtual
2025-04-16 | Virtual (Vancouver, BC, CA) | Vancouver Rust
Rust Study/Hack/Hang-out
2025-04-17 | Virtual and In-Person (Redmond, WA, US) | Seattle Rust User Group
April, 2025 SRUG (Seattle Rust User Group) Meetup
2025-04-22 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Fourth Tuesday
2025-04-23 | Virtual (Cardiff, UK) | Rust and C++ Cardiff
Beyond embedded - OS development in Rust
2025-04-24 | Virtual (Berlin, DE) | Rust Berlin
Rust Hack and Learn
2025-04-24 | Virtual (Charlottesville, VA, US) | Charlottesville Rust Meetup
Part 2: Quantum Computers Can’t Rust-Proof This!"
2025-05-03 | Virtual (Kampala, UG) | Rust Circle Meetup
Rust Circle Meetup
2025-05-05 | Virtual (Tel Aviv-Yafo, IL) | Rust 🦀 TLV
Tauri: Cross-Platform desktop applications with Rust and web technologies
2025-05-07 | Virtual (Indianapolis, IN, US) | Indy Rust
Indy.rs - with Social Distancing
2025-05-08 | Virtual (Berlin, DE) | Rust Berlin
Rust Hack and Learn
2025-05-13 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Second Tuesday
Asia
2025-04-22 | Tel Aviv-Yafo, IL | Rust 🦀 TLV
In person Rust April 2025 at Braavos in Tel Aviv in collaboration with StarkWare
Europe
2025-04-19 | Istanbul, TR | Türkiye Rust Community
Rust Konf Türkiye
2025-04-23 | London, UK | London Rust Project Group
Fusing Python with Rust using raw C bindings
2025-04-24 | Aarhus, DK | Rust Aarhus
Talk Night at MFT Energy
2025-04-24 | Edinburgh, UK | Rust and Friends
Rust and Friends (evening pub)
2025-04-24 | Manchester, UK | Rust Manchester
Rust Manchester April Code Night
2025-04-25 | Edinburgh, UK | Rust and Friends
Rust and Friends (daytime coffee)
2025-04-26 | Stockholm, SE | Stockholm Rust
Ferris' Fika Forum #11
2025-04-29 | London, UK | Rust London User Group
LDN Talks April 2025 Community Showcase
2025-04-29 | Paris, FR | Rust Paris
Rust meetup #76
2025-04-30 | Frankfurt, DE | Rust Rhein-Main
Kubernetes Operator in Rust
2025-05-01 | Nürnberg, DE | Rust Nuremberg
Hackers Hike 0x0
2025-05-06 - 2025-05-07 | Paris, FR | WebAssembly and Rust Meetup
GOSIM AI Paris 2025
2025-05-06 | Paris, FR | WebAssembly and Rust Meetup (Wasm Empowering AI)
GOSIM AI Paris 2025 (Discount available)
2025-05-07 | Madrid, ES | MadRust
VII Lenguajes, VII Perspectivas, I Problema
2025-05-07 | Oxford, UK | Oxford Rust Meetup Group
Oxford Rust and C++ social
2025-05-08 | Gdansk, PL | Rust Gdansk
Rust Gdansk Meetup #8
2025-05-08 | London, UK | London Rust Project Group
Adopting Rust (Hosted by Lloyds bank)
2025-05-13 | Amsterdam, NL | RustNL
RustWeek 2025 announcement
2025-05-13 - 2025-05-17 | Utrecht, NL | Rust NL
RustWeek 2025
2025-05-14 | Reading, UK | Reading Rust Workshop
Reading Rust Meetup
North America
2025-04-17 | Mountain View, CA, US | Hacker Dojo
RUST MEETUP at HACKER DOJO
2025-04-17 | Nashville, TN, US | Music City Rust Developers
Using Rust For Web Series 1 : Why HTMX Is Bad
2025-04-17 | Redmond, WA, US | Seattle Rust User Group
April, 2025 SRUG (Seattle Rust User Group) Meetup
2025-04-22 | Detroit, MI, US | Detroit Rust
Rust Community Meet and Conference Report - Ann Arbor
2025-04-23 | Austin, TX, US | Rust ATX
Rust Lunch - Fareground
2025-04-23 | Austin, TX, US | Rust ATX
Rust Lunch - Fareground 2025-04-23 | Spokane, WA, US | Spokane Rust
Community Show & Tell at Fuel Coworking
2025-04-24 | Atlanta, GA, US | Rust Atlanta
3rd 3RD TIME OMG YES!
2025-04-25 | Boston, MA, US | Boston Rust Meetup
Ball Square Rust Lunch, Apr 25
2025-05-01 | Saint Louis, MO, US | STL Rust
SIUE Capstone Project reflections on Rust
2025-05-03 | Boston, MA, US | Boston Rust Meetup
Boston Common Rust Lunch, May 3
2025-05-08 | México City, MX | Rust MX
Calculando con el compilador: Compiler time vs Run time
2025-05-08 | Portland, OR, US | PDXRust
Apache DataFusion: A Fast, Extensible, Modular Analytic Query Engine in Rust
2025-05-11 | Boston, MA, US | Boston Rust Meetup
Porter Square Rust Lunch, May 11
Oceania
2025-04-22 | Barton, AC, AU | Canberra Rust User Group
April Meetup
If you are running a Rust event please add it to the calendar to get it mentioned here. Please remember to add a link to the event too. Email the Rust Community Team for access.
Jobs
Please see the latest Who's Hiring thread on r/rust
Quote of the Week
IEEE 754 floating point, proudly providing counterexamples since 1985!
– Johannes Dahlström on rust-internals
Thanks to Ralf Jung for the suggestion!
Please submit quotes and vote for next week!
This Week in Rust is edited by: nellshamrell, llogiq, cdmistman, ericseppanen, extrawurst, U007D, joelmarcey, mariannegoldin, bennyvasquez, bdillo
Email list hosting is sponsored by The Rust Foundation
Discuss on r/rust
5 notes · View notes
track-maniac · 22 days ago
Text
Honestly if @typescript-official had enums with values inside like rust does I might just fall in love
6 notes · View notes
bizarre-furry-bastard · 2 years ago
Text
Tumblr media
93 notes · View notes
youboirusty · 2 years ago
Text
Tumblr media
If your language doesn't have a yeet keyword what are you doing with your life
121 notes · View notes
voltradar · 1 year ago
Text
Tumblr media
Got my tights, skirt, heart choker, and hoodie. Anything else needed to complie my Rust?
24 notes · View notes
aeriavelocity · 2 years ago
Text
Rust is DOOM Eternal
Rust makes you want to learn functional programming just by the fact that variables are immutable by default - and if you want to pass a mutable variable through a function, good luck.
You have to declare "&mut variable" in not only the function call, but also the damn function signature.
Compare that to Python where variables can't even be immutable.
Of course - this is probably a good thing. I'm a devotee of functional programming myself, so I'm biased, but to be fair, I didn't even know what functional programming WAS before I learned Rust.
If C is the Dark Souls of programming, Rust is the DOOM Eternal. (and Python is the Garry's Mod)
56 notes · View notes
itsjunetime · 9 months ago
Text
i built a little crate for tower-based rust web servers the other day, if anyone’s interested. it’s called tower-no-ai, and it adds a layer to your server which can redirect all “AI” scraping bots to a URL of your choice (such as a 10gb file that hetzner uses for speed testing - see below). here’s how you can use it:
Tumblr media
it also provides a function to serve a robots.txt file which will disallow all of these same bots from scraping your site (but obviously, it’s up to these bots to respect your robots.txt, which is why the redirect layer is more recommended). because it’s built for tower, it should work with all crates which support tower (such as axum, warp, tonic, etc.). there’s also an option to add a pseudo-random query parameter to the end of each redirect respond so that these bots (probably) won’t automatically cache the response of the url you redirect them to and instead just re-fetch it every time (to maximize time/resource wasting of these shitty bots).
you can view (and star, if you would so like :)) the repo here:
60 notes · View notes
agapi-kalyptei · 1 year ago
Text
Not gonna lie. I wrote my first programs 34 years ago but I never was a "real" developer in the sense that I'd write fast desktop apps, manage threads, and all that low level stuff. So learning Rust in the past few months, even if I have some very basic experience with programming in assembly, is still a lot to digest. However, today I got back to my test project and am really hyped that I have.... a button that increments a number.
"Ha, I can do that in javascript in 10 minutes." I mean yeah. Obviously. Anyone can. Here's the cool thing tho. I made mine overly complicated.
The UI looks as you'd expect it to, mostly a starter project leftovers:
Tumblr media
The HTML is as simple as can be, just plain HTML and javascript, no compile step. We live in stone ages here and we love it.
Tumblr media
The submit button has a simple handler in javascript:
Tumblr media
This is, once again, trivial, and all just from the template project. Bottom part says "when a user clicks this button, call "greet" function". The top part is the greet function that invokes a Tauri command also called "greet".
What's Tauri? An open source project that lets you write JS/TS/Rust applications with WebView and bundle them as stand-alone, self-contained, one-file applications for desktop, and starting with Tauri 2.0 (now in beta.2) also for Android (and later iOS). If you know Electron (Slack, Spotify, Discord etc all use Electron, they're just websites with Chromium and C++ code packaged around them).
Anyway. Tauri runs a Rust "server" application that serves your HTML/JS app, but also lets you run high-performance Rust code. Adding a command is relatively simple:
Tumblr media
Here's where things get interesting. For me.
Because I wanted to learn Bevy, a game engine written in Rust, because I want to learn how to write using a high-performance functional-programming-like pattern called ECS (Entity Component System), I have added Bevy to this project.
However, both Tauri and Bevy block on the main thread, so I had to find a tutorial on how to spawn Bevy in a different thread, and how to pass information to it. An example:
Tumblr media
#[tauri::command] turns a normal function into a Tauri command that I can call from HTML/JS. It injects resource called BevyBridge which is just two lines of code: #[derive(Resource)] pub struct BevyBridge(pub Sender<u64>, pub Receiver<;u64>);
Sender and Receiver being from crossbeam-channel bevy crate which is for sending data back and forth safely and quickly between individual threads.
so "state.0.send(1)" means I'm sending a 64-bit unsigned integer with a value 1 to the channel.
Tumblr media
And this is how to receive the message - inside of Bevy engine, in a separate thread. For simplicity, if I send zero, it resets the counter, and if I send any number it adds 100000 to the number, just for clarity. (Elsewhere I'm incrementing it by 1 on every game loop, so theoretically 60x a second. Or 15000x a second because Bevy is unreasonably fast and it doesn't need to render anything in this setup.)
And the best part is that with a single command (cargo tauri build) I get an .msi file, an .exe installer, both around 4MB, and a 11MB .exe file with no dependencies besides WebView (installed on every current desktop OS by default). There's just something about giving someone a floppy disk with an executable that you made yourself.
Tumblr media
Is it dumb? Yes. Does it make me happy? No. Does it make me glad, and very relieved that I'm not completely lost? You bet.
28 notes · View notes
suntreehq · 6 months ago
Text
Learning Rust and using my Visuals app to get some autumn vibes. (Video sped up by 1.25x).
I was hoping bombarding my subconscious mind with autumnal images would help me deal with the change of season. But I get enough autumnal vibes just looking out the window so maybe I will change it up to sunny imagery.
7 notes · View notes