Rust Programming

8414 readers
107 users here now

founded 5 years ago
MODERATORS
176
177
13
This Week in Rust 503 (this-week-in-rust.org)
submitted 2 years ago by [email protected] to c/[email protected]
178
 
 

Hey! I just made a new video about how to make blazingly fast unity plugins using rust! Let me know what you think!

https://youtu.be/BHxR4o09enA

179
 
 

Changelog can also be seen here: https://releases.rs/docs/1.71.0/

180
 
 

Rio - new rust terminal that is new and has very nice tabs, also powered by WGPU My mac setup

Ubuntu Rio setup

Windows Setup

Features:

  • Cross-platform
  • Tabs
  • Theme support
  • Custom font support

Made by raphamorim

181
182
183
5
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

I wanted to have a block visualization made in rust (like git[hub|lab]) to use for my personal website/blog, so I made one myself here the link to the repo https://github.com/tglman/tileline feel free to use and hack on it.

184
185
 
 

Rumor 1: Rust takes more than 6 months to learn – Debunked !

...

Rumor 2: The Rust compiler is not as fast as people would like – Confirmed !

...

Rumor 3: Unsafe code and interop are always the biggest challenges – Debunked !

...

Rumor 4: Rust has amazing compiler error messages – Confirmed !

...

Rumor 5: Rust code is high quality – Confirmed! ...

186
 
 

From the post:

Looking for people to try out cargo-native "cargo script"! This let's you put cargo in the shebang line of your rust source with an optional, embedded manifest (Cargo.toml). We have enough implemented now to give people a good feel for what we are working towards. See https://github.com/rust-lang/rfcs/pull/3424#issuecomment-1609687109

187
 
 
188
 
 

Google's open source blog put out a post on their experiences with Rust so far; definitely an interesting read!

189
 
 

I recently made a community for bird identification (check us out here ).

I would like to make a bot that would take in a bird name like this [[American Robin]] and comment back with links to more information. I can do the links for birds easily but the bot side I don't know. Does anyone have any examples of Lemmy bots written in rust that do something similar? Or at least a source on where to start?

The final code would be open source if that matters to people. Thank you in advance.

190
 
 

I want to create a global hash map that maps strings to vectors of colors. This data needs to be queried by multiple functions and should just be hard coded into the program. That doesn't seem possible.

Now, how is the right (tm) way to do something like that in Rust? What if you need just a bunch of data structures from the beginning of the program until its end where some of the data needs to allocated?

191
8
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

I made a 2D platformer randomization crate called Shiftnanigans (https://github.com/AustinHellerRepo/Shiftnanigans) as part of my work on the open source game Jumpy (https://github.com/fishfolk/jumpy). Within the map editor of Jumpy, the Randomize button will randomize the placement of tiles and elements, maintaining the general structures of the map. I've described the two abstract concepts and sets of structs used to accomplish this functionality below. This is just a general overview, but I am happy to elaborate further if anyone has questions about the algorithms and data structures used.

Web demo (click Map Editor -> Open Map -> Level #12 -> Randomize (in the top right)): https://fishfolk.github.io/jumpy/player/latest/

The PixelBoard and PixelBoardRandomizer

In order to randomize a 2D platformer or tile-based map, the PixelBoardRandomizer takes in a grid of "pixels" as a PixelBoard, detects wall and non-wall pixels, groups them together, and finds locations for those groups such that no two groups overlap while also maintaining contact with adjacent walls (or not, as applicable). Wall chunks that do not make contact with the corners are considered "wall segments" and can shift around along the edge of the map. Each randomized PixelBoard can be repeatedly randomized itself without affecting the size or adjacency of pixel groups, allowing repeated execution of the randomization function on a previously randomized PixelBoard. To optimize this process, shifters (described below) are ultimately used to compare pixel group locations to each other, incrementing to the next randomized location for the specific pixel group. All pixel groups are ultimately compared to each other to ensure that they are all valid together in some combination of locations. Instead of placing all of the pixel groups down randomly one at a time just to find out that the last pixel group won't fit (ultimately because the very first pixel group is in a bad spot), each pixel group is paired up with each other pixel group as a cartesian product and is compared together.

The PixelBoard and PixelBoardRandomizer Continued

This is where it gets a little complex. Each pair of pixel groups iterates over all possible locations for those pixel groups in a round robin cycle, allowing each pair of pixel groups an opportunity to check if their current random locations are valid together. As valid pairs of pixel groups are discovered, a hypergraph is filled with connecting edges between hypergraph node's subnodes where each hypergraph node is conceptually a pixel group, a subnode is a location for that pixel group, and the edge indicates that the two locations of each pixel group are valid together. Once a cliché is discovered between all hypergraph nodes, that indicates that each pixel group location connected together within the cliché are all valid together and would form a valid, randomized PixelBoard.

Shifters and Incrementers

Shifters are just 2-dimensional skewed arrays with a pointer to a current cell where navigation through the array is defined by a few basic operations: forward, backward, and increment. The shifter starts with a column pointer in the 0th row's 0th column. You can imagine that an increment moves the current column pointer down the array, a forward action creates a new active column pointer in the next column at the top row of the array, and a backward action removes the current column pointer and makes the previous column pointer active where it left off. If any action is not possible a None is returned, indicating that a backward action must occur so that the previous column can increment once, and then return forward at the top of the column again with a new column pointer, ultimately iterating over all possible combinations of column cells. An incrementer returns a collection of cells. One of the most useful applications is being basically a wrapper on a shifter that returns, with each iteration of the incrementer, a collection of cells (one per column) as a permutation of the underlying shifter as it moves forward and increments, only moving backward with subsequent iterations of the incrementer that would cause the underlying shifter to increment or move backward and then move forward again with each iteration. With these two data structures understood, it is possible to create many interesting variations of shifters and incrementers that "fail fast" while performing some interesting traversal of a state space. For example, the pair of pixel groups iterate over their possible locations in an expanding square sequence/permutation using the ShiftingSquareBreadthFirstSearchShifter. This could be improved upon by implementing a decrement movement on shifters and utilizing that functionality to search in a triangular shape outward instead of a square.

Efficiencies:

  • Shifters make it very easy to find invalid pairs of column cells and fail fast as opposed to generating a long list of column cells just to discover that the first pair are invalid together.
  • Only pairs of pixel groups that could ever conflict or overlap are compared (so one wall isn't paired with another wall, for example).
  • When a new edge is added to the hypergraph, that edge is the starting point for searching for a cliché within the hypergraph.
  • A cliché search is only performed if each hypergraph node's subnode for the new edge is connected to all other hypergraph nodes at least once.

Next steps:

  • Allow for specifying that "wall segments" should not shift around, greatly improving performance but reducing degree of randomness.
  • Create a few examples in the Github repository based on common uses of this functionality
  • Implement a decrement action for shifters, permitting more efficient state space search algorithms.
  • Create trait implementations that more easily convert existing iterators into variations of shifters or incrementers.
192
 
 

[disclaimer: initially posted on Reddit r/rust]

unrar is a library for listing and extracting RAR archives.

Hi lemmyrs!

Almost 8 years ago, I release my first Rust crate. Today, before I leave Reddit at the end of the month due to the recent controversy, after months and years working on and off on this update, as a parting gift, I'm happy to announce the crate's biggest release ever. This really is a milestone release that, among others, allows one to extract files directly into memory -- something people have been asking forever how to do.

I've also completely rewritten major parts of the library and am very proud of the way things are looking right now. Utilizing the typestate pattern, the library enforces correct usage at compile time, only exposing methods when they make sense (depending on a combination of open mode and current cursor position).

Before this release, the library was hard to use and it was not possible to skip some files in the archive while, for instance, extracting others. One operation had to be chosen for all files. That has changed now. However, the drawback is that iterating archives is now a bit harder since the Iterator trait is not implemented for archives that are opened in Process mode (since it's hard to enforce an operation at call-site). I have a few ideas how to improve this going forward but input is also always welcome.

Anyway, this sets the groundwork architecture and paves the way forward for upcoming releases where ergonomics and other improvements like error types can be the focus.

Another major focus of this release was documentation: all API items are documented now except for very few exceptions. The crate docs also features a very extensible introduction as well.

GitHub repository can be found here: https://github.com/muja/unrar.rs

Feel free to discuss / ask questions here or over on Reddit.

Thanks!

193
 
 

Say I want to have a struct called Tile that will have a suit (let it be a string for simplicity's sake) and a number. This number can only exist in the range of 1-9.

In Nim, for example, you can do something like this:

type 
  Tile = object
    suit: string
    num: range[1..10]

var t = Tile(suit: "test", num: 9)
echo t.num # 9
t.num += 2 # OverflowDefect

How can I do such a thing in Rust? I can only think of one way: not allowing the number to be out of range in the "new" constructor and then adding auxiliary methods (add, sub, etc.) that do bounds checking. This solution seems too complex, though. There might be a way to do this using various range traits, but I can't seem to figure out how.

194
 
 

Hi fellow Rustaceans. I am new to rust and web stuff and I want to make battleship game with rust as a server side and android as a client. Will Rocket/Actix web be ok if I want to create something like a lobby/room for players, or will sockets be better suited?

195
 
 

I'm an experience software engineer, but I have a had a hard time just "jumping into Rust". I really want to know the language, but I've struggled to build something in it.

However, I watch YouTube videos while I run on the treadmill at the gym. I've tried to find a series that explains the Rust borrower and some of the concepts surrounding that, but I've been unable to find a good one. I've watched ~15 videos on Rust, but a lot of them just stop after the basics. They are supposedly "series," but once they hit the borrower, they stop the series prematurely. I'm not sure why.

But if anyone knows of a good YouTube channel that sort of does a "Rust language overview", which does a reasonable job of covering Rust's flavor of references, structs, generics, Box, borrowing, and some of the advanced features, I'd appreciate a link. I'll be going on a 3-4 mile run tonight and I'd love something to occupy my brain so I don't suffer so much.

196
 
 

cross-posted from: https://beehaw.org/post/570507

After the (temporary) defederation announcement of earlier i checked the Lemmy repo to see if there was already a ticket on the federation limiting option like Mastodon's that people mentioned Lemmy doesn't yet have. Not only i didn't find it, i also saw that there's about 200+ open tickets of variable importance. Also saw that it's maintained mostly by the two main devs, the difference in commits between them and even the next contributors is vast. This is normal and in other circumstances it'd grow organically, but considering the huge influx of users lately, which will likely take months to slow down, they just don't have the same time to invest on this, and many things risk being neglected. I'm a sysadmin, haven't coded anything big in at least a decade and a half beyond small helper scripts in Bash or Python, and haven't ever touched Rust, so can't help there, but maybe some of you Rust aficionados can give some time to help essentially all of Lemmy. The same can be said of Kbin of course, although that's PHP, and there is exacerbated by it being just the single dev.

197
 
 

Verus is a tool for verifying the correctness of code written in Rust. Developers write specifications of what their code should do, and Verus statically checks that the executable Rust code will always satisfy the specifications for all possible executions of the code.

198
 
 
199
5
This Week in Rust 499 (this-week-in-rust.org)
submitted 2 years ago by [email protected] to c/[email protected]
200
 
 

cross-posted from: https://lemmy.one/post/123519

Skip to around 24m:00s

view more: ‹ prev next ›