rustological

u/rustological


r/rust•

using llama.cpp via remote API

🙋 seeking help & advice

There is so much stuff going on in LLMs/AI...

What crate is recommended to connect to a remote instance of llama.cpp (running on a server), sending in data (e.g. some code) with a command what to do (e.g. "rewrite error handling from use of ? to xxx instead"), and receive back the response. I guess this also has to somehow separate the explanation part some LLMs add from the modified code part?

04

r/rust•

TLDR: I've got an older 4-core laptop. Now I do everything serially and only one core is used - which is becoming too long. What is a recommended lightweight crate to implement a "pending jobs" management and keep all cores busy?

Long version: Imagine a first "stage" is to read in 100 files and search for and read data from these files. If data is found in a file in "stage 1", then another "stage 2" does something with the data - lets say 30 out of the original 100. Then a "stage 3" should aggregate all the outputs again. Instead of doing one job after another, every available core should be busy with either a file (stage 1) or what comes after (stage 2). Basically, management is needed: a

07

r/rust•

Rust (code) in documentation with Typst

🙋 seeking help & advice

Early evaluation of Typst (https://github.com/typst/typst) suggests that we should use Typst as documentation markup language (it is faaaast and easy crossplatform) for a new coming 2025 project that is starting from scratch.

What is the community suggested best package to highlight Rust code in Typst?

How to automate the extraction of fn xyz or struct abc (with the /// docs?) from current thisfile.rs into the documentation build process?

...any experiences appreciated :-)

157

r/rust•

Fastest text line-by-line ingestion?

🙋 seeking help & advice

Reading a text file line-by-line is a common problem, but... what is a FAST way to ingest/parse LARGE (GiB) text files?

  • line by line, string slice of full line is passed to a function for further processing (either copy and keep, or ignore and go to next line)
  • either read from file or from stdin
  • allows to set custom max length of line (denial of service prevention)
  • input can be several GiB of size, so no "just read into memory at once, then iterate over it" -> read chunk by chunk -> needs stitching when line goes over chunk boundaries
  • keeps track of line number and absolute offset location in input data
  • can handle 0d0a as well as 0a line ending
  • is fast

...any recommendations

111

r/rust•

Searching I have found some projects, but I wonder what is the current state of art to implement a distributed task/jobs management. Let me explain:

I have xxxxx jobs/tasks. There are different functions, each one takes a specific struct/data as input and produces one or more specific struct/data as output, meaning one or more new jobs - or a "final" state for this data.

Thus, a manager 1) searches in the data pool if there a structs that are known to be input to known functions, if yes 2) allocates a worker core locally, spawns a thread and executes the function with that input, and 3) on function completion returns data struct to pool. Ideally, this does not only work with local free CPU

36

r/rust•

Termux + Rust + ?

🙋 seeking help & advice

Got a new tablet (thanks Black Friday...) and tried coding on-the-go (the train...) again. Turns out, Termux plus rust compiler plus bluetooth keyboard is a nice combination and works well! https://i.imgur.com/mdHYw1e.jpeg

Open question is, what editor to use? Plain nano is not productive, syntax checking, smart code completion and similar amenities of a real IDE would be nice. Helix is available as package, but I never got my brain to like modal editing.

Any other options than Helix - or do I need to really try to work with it it?

729

r/rust•

I got a problem of

produces XML | filter | structured output of certain extracted data fields

The current implementation of "filter" is ~400 lines Ruby (with Nokogiri) and produces as structured output yaml. It is old, needs some bug fixes, and always installing Ruby plus dependencies just for this is too much complexity. So.... maybe rewrite into a new standalone Rust executable would be nice?

Searching for XML libraries on "blessed.rs" yields nothing. Searching on lib.rs and creates.io yields hard-xml, strong-xml, fast-xml, easy-xml, quick-xml, ..... WTF?

I need a recommendation for a XML/HTML parsing library that a) parses the input into memory (its small enough) b) provides an API wi

12

r/rust•

Call methodA or methodB, globally

🙋 seeking help & advice

One way to call methodA or methodB, if depending on different platforms, is via conditional compilation https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-macro For example, compilation on Windows and Linux requires different handling of filenames/paths. Ok, makes sense, like with C.

However, how to implement a dynamic choice on startup? Say, I'm running Linux, and either in a terminal/TUI or under X/GUI. On startup I have to run some checking code first, and then I want to set "output a string so user surely sees it" needs to be either writeTUI(..) oder writeGUI(..), globally, throughout the rest of the program.

Trait of methods with variants, then specific trait obj

126

r/rust•

Use Intel iGPU in Rust for... what?

🙋 seeking help & advice

I was wondering, what can I use the Intel internal GPU (the one included with Intel CPUs) for in Rust?

Not graphic things, but algorithms, searching, comparing, hashing, ... large data chunks - faster than with only CPU cores.

Recommended crates? What drivers are required - probably mesa? Vulkan?

115

r/rust•

LaTeX highlighting for Rust code

🙋 seeking help & advice

I just found out that the minted LaTeX package supports Rust code highlighting :-) However, it could look prettier...

...what is your favorite example configuration of minted for Rust code highlighting? :-)

10

r/rust•

Rust for working with binary protocols

🙋 seeking help & advice

I have to work with a legacy hardware device, communication is with a binary protocol over serial port, and I wonder what are the pro/cons of implementing this in Rust (also for my boss ;-).

Binary protocol: Imagine a blob of bytes is a command, first two bytes is length of packet, next byte is selector of substructure A,B,C,... then further content is depends on substructure type. Not all fields are static size, some are unfortunately dynamic or present/absent. Also there is endianness of some fields that needs to be converted.

One obvious solution is to manually write this, my research led me to https://crates.io/crates/bytebuffer or https://crates.io/crates/bytemuck. But that is tedious

111

r/rust•

We've been using a generator for certain reports at work for years. It is currently written in Python+Reportlab (https://pypi.org/project/reportlab/). It has served us well, however a) it sometimes produces broken PDFs - nobody knows why (original coder is gone), the solution is to randomize the input parameters a bit until it works again and b) maintaining a Python installation plus reportlab libs etc. over the years just for generating these PDFs became annoying.

Is the solution to rewrite it in Rust? This is the chance to find the bugs (if they are in our code and not some lib) and ideally the result is a single standalone binary (that also embeds the ttf fonts needed), and this then jus

14

r/rust•

What is THE choice of tool to automate extraction of Rust source snippets for documentation building?

For example, from a certain .rs file I want to extract a certain function, or a data structure - then remove leading spaces, apply highlighting, and then include the snippet in a LaTeX document with a much longer explanatory text and context. Hmm... highlighting may be better done at the LaTeX side - which is the best package for that currently?

I imagine something scriptable like: extractthisfunction perform_computation src/foo/bar.rs >doc/fn_perform_computation.tex

Happy for hints :-)

4411

r/rust•

Coming from a Python world, in Python a quick, interactive development is very easy: Keep project open in full IDE. Then use Jupyterlab for interactive testing -> A Jupyter notebook that just "import foo", write some testcode calling a function, and enable autoreload for changes (https://ipython.org/ipython-doc/dev/config/extensions/autoreload.html) in Jupyter.

So whenever a line is changed in IDE and saved, Jupyter auto-reloads the code and it can be immediately called from notebook cells and played around with. Nice!

How to reproduce this fast, iterative flow with a rust project? Full rust project open in IDE. Jupyter also has evcxr rust plugin. Calling functions from Rust to Rust is

74

r/rust•

What is the go-to package to generate from data pretty pictures that can be included into webpages, either then written to a html file or served directly via e.g. Rocket?

My understanding is the Altair package https://altair-viz.github.io/ from the Python world does this: Python code generates a Vega-Lite https://vega.github.io/vega-lite/ specification along with the raw data output as json, and these then can be bundled together into a webpage where the vega.js Javascript-based renderer then does the actual visualization work in the browser. Does a similar project for Rust exist? What do you use when you want to e.g. serve a dashboard from Rust and need visualizations?

50