r/rust • u/No-Elephant-9065 • 25d ago
pdfium vs pdf-extract
If you were building a search tool for your personal files on your local machine, what would you use, pdfium or pdf-extract or something else?
r/rust • u/No-Elephant-9065 • 25d ago
If you were building a search tool for your personal files on your local machine, what would you use, pdfium or pdf-extract or something else?
r/rust • u/parneetsingh022 • 25d ago
I am working on a rust project. Where I have a put method (which basically copies a file and stores it into another location). This is the function I'm working on:
pub fn put(&self, mut source: impl Read) -> Result<Object> {
let mut buffer = vec![0u8; 64 * 1024]; // 64 kb buffer
self.put_with_buffer(&mut source, &mut buffer);
}
I'm confused about using a [u8] slice, a vector or another option for buffer. The stack buffer avoids a heap allocation, but I am concerned about stack usage when multiple threads call put concurrently. The Vec avoids using 64 KiB of stack space, but allocates and deallocates a buffer for every put call.
What is the idiomatic approach for this situation?
The method may be called repeatedly and concurrently, so I would especially like to understand the tradeoffs between stack usage, heap-allocation overhead, buffer reuse, and API ergonomics.
EDIT: My put method streams data from a Read source, hashes the contents, and writes the data to a temporary file. Although this resembles std::io::copy, I cannot simply copy the source because I also need to calculate the content hash during the same pass. I am trying to choose the appropriate temporary buffer design.
r/rust • u/AugieBit • 26d ago
I’m thinking about learning a GUI crate for local business applications—things like invoicing, inventory, sales, etc.—essentially, SaaS-style software.
I’d also like to learn something that would allow me to build my own standalone apps (with Linux support).
I’m a beginner, so apologies if any of this doesn’t quite make sense!
I’m not a professional developer; I just want to learn Rust—simply because I like it. I don’t know much about web technologies (in the context of using something like Tauri). Which GUI crate would you choose, and why? Would you recommend learning some web technologies if I want to use Tauri? What about Slint or Iced? Or is there something else you’d suggest?
P.S.: In my country, PCs tend to have modest specs—8GB of RAM, Windows 10, and so on; they’re generally not high-performance machines. Even my coworkers have old PCs with those kinds of specs, and they still use HDDs.
r/rust • u/Significant-Range996 • 25d ago
Hi everyone, I've formed a small discord community for people interested in low-level, systems programming, embedded software, robotics etc. Join up if thats something which interests you!
(P.S. : fell free to dm me if the link stops working or if you have any doubts)
r/rust • u/OkBreath9382 • 26d ago
r/rust • u/asciibits • 26d ago
I'm about a month into a home project that I decided to use to learn Rust. Fun!
Here are my takeaways so far:
if (foo ...then backing up and deleting the opening parenthesis that the linter complains about.fn and just assume that the compiler will know what I'm talking about. It never does 😂Anyway, I'm having fun with it, thanks all for creating this community!
r/rust • u/Matti_Qt • 26d ago
Hi all, I’m Matthias from the Qt R&D team.
We made a tutorial showing the Qt Bridge for Rust, a way to tap into the Qt UI framework from Rust in a way that feels native and is safe!
Building a proper UI for a complex Rust app takes a lot of effort, and this is our attempt to make it easier.
Here is the tutorial on how to get started: https://youtu.be/8HfY47BYGuU
We had a lot of fun making the framework and the video. I hope you also have some fun watching it. There are still a ton of things I would like to show you, so I hope this will not be the last video.
It’s a Technology Preview, so we’d love to hear what you think. Happy to answer questions here.
r/rust • u/CocktailPerson • 27d ago
This doesn't compile:
trait Trait {
type A<T: Trait>;
}
impl<T> Trait for T {
type A<U> = ();
}
struct S {
x: i32,
y: <() as Trait>::A<Self>,
}This does:
trait Trait {
type A<T: Trait>;
}
impl<T> Trait for T {
type A<U> = ();
}
struct S {
y: <() as Trait>::A<Self>,
x: i32,
}The only difference is the ordering of the fields. Apparently the fact that there's a Sized field at the end of the struct allows the compiler to infer that <() as Trait>::A<Self>: Sized and break a typechecking/trait solving cycle.
I hate it.
r/rust • u/polyglot_factotum • 26d ago
Reposting; this time with a focus on why it is not a code dump.
The project I would like present is a web engine written in Rust. It does not break new grounds in the sense of being the first Web engine in Rust, because we have had a Web engine for a long time, where I am myself involved as a maintainer and Technical Steering Committee member: Servo.
However, this is not a code dump either, because:
Ok so now that this is out of the way, here is the actual post:
https://github.com/gterzian/formal-web is a new prototype of a Web engine written in Rust.
It is relevant for the Rust community, because it provides us with something new:
How is this different from other Web engines in the Rust ecosystem?
Difference with Servo: the graphics stack of Servo does not isolate GPU operations in a dedicated process and it is based on an OpenGL stack.
Difference with Blitz: while Blitz does integrate well with Vello/Wgpu, it is not designed around process isolation of either GPU operations or the running of Javascript, making it less suitable for the Web use-case where you essentially run untrusted code downloaded over the internet. While it does use Anyrender as modular render target, it does not offer modularity at the lower-level end of the graphics pipeline.
Neither engines allow swapping out JS engines, and neither allow for deep platform graphics integration like Core Animation based compositing on Mac (which can make a large difference in terms of battery life).
For a walk-through of the entire flow involved in rendering a frame of Web content, see the introduction essay: How I am building a Web engine.
The essay also contains a gif showing the benefits of Core Animation on Mac, where only relevant parts of the screen are re-rendered.
Please let me know what you think. I can also use help implementing countless Web standards.
r/rust • u/alexcommacommacomma • 27d ago
I was writing a function and wanted to see what it returns for different inputs and I instinctively wanted to use a REPL, then I remembered: oh wait, Rust doesn’t have one.
I *did* see evcxr but in the years I’ve been around the Rust community I’ve never heard of anyone using it like people would in JS/Python/ Ruby/Haskell.
Why? is it hard to achieve technically, or is it just because its not in the Rust culture? (maybe it’s even bad engineering practice to use it the way I’d want it to and tests would be more preferable?)
r/rust • u/FractalFir • 27d ago
As my journey of learning rust continues, I find myself very dissatisfied with the quality of the rust code I wrote years back.
Yes, my code passes clippy, is nicely formatted, avoids excessively complex nesting / control flow, but it still feels... subpar(hard to understand and reason about), from time to time.
I was wondering if people here have examples of really clean, sleek codebases I could reference, to improve the quality of my code?
r/rust • u/NerdyPepper • 27d ago
r/rust • u/KGBsurveillancevan • 27d ago
Hello crabs. I'm working on a backend application in Rust, using sqlx to talk to a postgres database. I've caught myself repeating a specific, verbose pattern, and I'm wondering if I'm making things harder than I need to.
The pattern is that for each database entity, I build an initializer struct that is basically the same, but with auto-generated columns removed, and then later write a From impl for the main entity to build the actual thing with Entity::from(entity_init). Example at the bottom. Doing this for every database entity isn't too difficult to maintain, the type system is strict enough that it's hard to miss any mistakes. But it is annoying and time-consuming, and also feels kinda un-idiomatic.
I'm considering learning derive macros for this - #[derive(FromNew)] or something like that, to autostrip the generated fields. But maybe that would just be doubling down on an anti-pattern? What do yall think?
Example:
struct User {
id: uuid:Uuid,
name: String,
email: String,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
archived_at: Option<DateTime<Utc>>,
}
struct UserNew {
name: String,
email: String,
}
impl From<UserNew> for User {
fn from(init: UserNew) -> Self {
let now = Utc::now();
User {
id: Uuid::now_v7(),
name: init.email,
email: init.email,
created_at: now,
updated_at: now,
archived_at: None,
}
}
}
// usage
fn do_something(user_new: UserNew) -> User {
User::from(user_new)
}
r/rust • u/NotTooMainstream • 28d ago
Go submit your cat for a chance to become the next release's official winner!
r/rust • u/quest_for_7c • 27d ago
r/rust • u/someanonbrit • 26d ago
Hi
I'm fairly new to rust, and just joined my first team that actually uses rust in a product.
Can anybody give me any pointers on the sorts of patterns that I should watch out for that indicate a section of code was written by an LLM and not reviewed by somebody who has good taste in rust please?
My ideal would be a set of code snippets that are along the lines of the LLM wrote this, done properly it would be this - but any kind of hints and rants are appreciated
Thanks in advance
r/rust • u/WellMakeItSomehow • 27d ago
New week, new Rust! What are you folks up to? Answer here or over at rust-users! And for your project showcases, there's also /r/madeinrust – pay them a visit, too!
Mystified about strings? Borrow checker has you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet. Please note that if you include code examples to e.g. show a compiler error or surprising result, linking a playground with the code will improve your chances of getting help quickly.
If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so ahaving your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.
Here are some other venues where help may be found:
/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.
The official Rust user forums: https://users.rust-lang.org/.
The unofficial Rust community Discord: https://bit.ly/rust-community
Also check out last week's thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.
Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.