1201
11

I suppose I should start posting updates here too. 😁

1202
23

Let me start by noticing, I am not interested in playing a game of Tic Tac Toe, nor programming any form of "AI". With that out of the way, let me give some background:

I have found Rust, with its ownership model, frequently nudges me to rethink whatever I am building. Usually it involves fixing some structs / enums, to avoid references. Correctly structuring an object can make me avoid lots of headaches later when I actually add functionality.

One thing I noticed that helps is understanding what kind of properties should the data have? Should it maintain a certain order, or can it be unordered? Are all of the values unique, or can it have duplicates? All of these details are very important. It is wrong to just shove everything into a Vec. A Vec implies ordering and duplicates, which could be a bad model. We need to choose something which most closely represents the data.

Ok, enough lecture. Onto the Tic Tac Toe grid. Observing this grid provides me with a few important properties:

A Tic Tac Toe grid can be rotated clockwise or counterclockwise, and the game is still the same. The grid can also be flipped over horizontally or vertically and the game will be the same. To decide if anyone won, we just need to see if any rows have 3 of the same value. The rest of the grid does not matter.

I am trying to figure out the best memory model would best represent this behavior. How to build a grid whose orientation does not matter?

Ideally, all of these values should be represented in memory exactly the same way:

  X|O|   X| |    | |
   |O| = O|O| = O|O|
   | |    | |   X| |

But how to do this? One way I was thinking, is perhaps instead of saving a grid at all, we should just be keeping track of all of the rows.

  • [X, O, E] (E = Empty)
  • [O, O, E]
  • etc for all the other rows..

However there are several problems with this model:

  1. The same cells are owned by multiple rows. This is not good. Perhaps the rows can hold a reference to the cells?
  2. The ordering of each row should not matter. So this shouldn't be an array. A better representation may be a Set or Bag/Multiset.

#1 continues to bug me. If we have rows holding references to all of the cells, then it will be hard to update any of them because of rust's restrictions on multiple mutable borrows. Or am I wrong here? How can I update a cell using a reference from a row? Where would the cell live anyway?

It doesn't seem to help to declare the rows inside of the cells, because that leads to cyclical references.

I continue to mull over this problem with not much success. I hope someone can help me discover a better path forward.

1203
13
From C to Rust (programming.dev)
submitted 3 years ago by ron@programming.dev to c/rust@programming.dev

Any book out there that can ease me into Rust from C?

1204
31
2022 Rust Survey results (blog.rust-lang.org)
1205
21
submitted 3 years ago* (last edited 3 years ago) by BehindTheBarrier@programming.dev to c/rust@programming.dev

I'm super new to Rust, like a day old really.

But I tried a program made in Rust on Windows, and it refuses to work.

Never prints anything. Just straight up instantly dead. Long story short, this thing relies on some linked stuff like ffmpeg in some form. So, I did my best trying to gather all the things it needs per github issues, reddit and other souces. And the end result was that it now spent 0.1 s longer before crashing, actually leaving time for some error in the Windows Event log. Nothing useful there either as far as I can see.

So I clone the repo and get the required things to compile Rust, and I managed to build it from source at least. The executable doesn't run, but the Run in VS Code works, somehow. It prints the error messages corresponding to missing input. So i try to debug it, but nothing happens. No breakpoint is hit, and nothing is printed in the terminal, unlike when using Run or cargo Run. I can also just strip out everything it does in the file the main function is in, and it will hit breakpoints. But that didn't help me find out what is missing/broken though.

So what the difference, is there a way to catch and prevent Rust from just going silent, and actually tell you what dependencies it failed to load?

My entire reason for getting it running locally is to fix that. Because no one sane wants to deal with a program that doesn't tell you why it will not run... And when debugging also does nothing... I'm out of ideas.

The program is called Av1an for reference, and it's a video encoding tool. I used a python version before they migrated to Rust, and wanted to give it a try again.

Edit: Wrote linked library, but i think the proper term is dynamic libraries. I'm really not good with compiled programs.

Update: Figured it out. Had to copy the out files from the ffmpeg compiled stuff back to the executable. Apparently Cargo Run includes that location when looing for the files, while running from the command line clearly doesn't.

But the biggest whiplash, was that I got a full windows dialog popup when i tried to in the exectuable in CMD instead of Powershell. Told me the exact file I was missing too. I know PowerShell is a bitch when piping stuff, but I'm amazed no other program or error message could hand me that vital information. Fuck me, I wish I had tried that from the start....

1206
6

Hi everyone! I started learning rust about 3 months ago and had a sort of working version of this for my own needs, but spent some time (maybe lots) cleaning it up, testing it, and making it worthy of publishing.

https://crates.io/crates/cypher-dto

It's for working with Neo4j (cypher query language). It aims to assist in creating manual queries but provides unitary CRUD operations for nodes and relationships out of the box. Some other niceties:

Generates new(), getter methods, and a builder struct, and copies doc comments to them.

Has 'smart' handling of created/updated timestamp fields.

Supports multi-valued primary keys; uses the term "identifier" for that set of fields.

1207
15
1208
6

Im trying to use iced for the gui in an audio plug in I'm building, but I keep seeing discrepancies in how to accomplish this.

On the iced github page, it says that to implement the Sandbox trait, you use this signature: fn view(&self), yet in the documentation it says to use view(&mut self). When I try to use the non-mut version, I get an error saying that it expects self to be mutable.

I also stumbled across iced-pure, which seems like a better idea. But I need to use a NumberInput widget from the iced-aw crate. Unfortunately, these widgets are not pure.

So how do I go about creating a gui using NumberInput? Do I need to create the widgets myself to make them pure? I'd like to use other widgets from the iced-aw crate too, so that wouldn't be ideal

Or do i have to use the mutable version of view? If so, why does github say to use non mutable? Is this specific to certain versions of iced? If the newer version of iced uses a non mutable view function, does that mean it's pure? Have the iced-pure changes been merged into iced?

1209
19
submitted 3 years ago* (last edited 3 years ago) by u_1f914@lemmy.world to c/rust@programming.dev

A small Ferris on !canvas@toast.ooo .
One other person already started helping.
Coordinates are (90, 780).
https://canvas.toast.ooo/#x=93&y=793&scale=19.67

Template URL for pasting:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAPtJREFUWIXtVTsOhCAQHYklhdUewHi6Lan3CBtPaDyDhSUJW5kgmRlnAN2GVwnzeY/HEAEaGhr+jE5b4J0NXLyfd1VPcfIVca4Qcwc5VYPtmTSYJuWQY7XUN+oAJaZUBLY2XPAuxPNxGpQnBKTDabggh+/rA/28k2sJOQDxDCVOHGTeWXQtIScFSEVogYlgXwFXKCGT1IkcSBtx7mCk3tmQc4hq11DUJ7yhSERp/QnbNFYfTNHPCBNSS0yWAACAYVm7GiLEArZpDMOy6icZ+KsjBVzZHAs68uL8dE/lFpYsaU6RZTmQNtDYX2U+4iugToS5wuUXiSlq0MDgB0tRtTR5tH/TAAAAAElFTkSuQmCC

1210
6
submitted 3 years ago* (last edited 3 years ago) by TheRealPomax@mastodon.social to c/rust@programming.dev

Hm, how do I make @rust compile some code as crate-type = ["cdylib"] on Windows in a way that doesn't rely on non-existent downstream .dll files?

Compiling the following bare minimum code makes the resultant .dll link to libm.dll, which is not a thing, Windows does not have a libm.dll

pub fn add(a: usize, b: usize) -\> usize { a + b }  
1211
2

I know there's mockall which seems to be geared towards implementation methods and traits, but I'm wondering about just structs with non-function properties.

In my tests, I want to define initialized structs with values. It works fine to just do it like I normally would in code, but I'm wondering if there's more to it than that. Like if I have a cat struct:

struct Cat { name : String } `

#[cfg(test)] pub mod test { use super::Cat; fn test_create_cat() -> Cat { Cat { name. : String::from("Fred") }; }

That's fine, but should I be doing it differently? What about mockall, is it not meant for structs with properties?

1212
12
The Quest for Piet (notgull.github.io)
1213
13
1214
15
1215
10
This Week in Rust 506 (this-week-in-rust.org)
1216
15

For some reason, it seems popular for GUI crates to use the GPU. I just want to make simple widgets, for like a calculator.

No fancy graphics. I want it quite lightweight.

For some reason, popular GUI crates love to do everything through a GPU, which bumps up the memory / cpu use significantly.

1217
22
1218
6
1219
9
submitted 3 years ago* (last edited 3 years ago) by nerdblood@programming.dev to c/rust@programming.dev

for example, I have a file structure that looks like this:

action/
   attack.rs
   attack.test.rs
   mod.rs

But this doesn't work in the mod file:

pub mod attack.test;

and neither does:

pub mod "attack.test";

1220
25
submitted 3 years ago by u_1f914@lemmy.world to c/rust@programming.dev

"A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm."

This release includes among many other things:

  • A software renderer
  • Text shaping, font fallback
  • Incremental rendering
1221
12
1222
16
1223
33
A JVM in Rust - Part 3 (andreabergia.com)
1224
12
submitted 3 years ago* (last edited 3 years ago) by orangeboats@lemmy.world to c/rust@programming.dev

For context: I am trying to write a Rust wrapper over a C library.

Like many C libraries, most of its functions return an int. Positive return values are meaningful (provides information) and negative values are error codes.

To give an example, think of something like int get_items_from_record(const struct record *rec, struct item *items). A positive value indicates how many items were returned. -1 could mean ErrorA, -2 ErrorB, and so on.

Since this is Rust, I want to represent this kind of integer as Result<T, E>, e.g.:

enum LibError {
    A = -1,
    B = -2,
    // ....
}

// LibResult is ideally just represented as an integer.
type LibResult = Result<NonNegativeInteger, LibError>;

// Then I can pass LibResult values back to the C code as i32 trivially.

Is there a way/crate to do this?

1225
13

Hello! I'm a 3rd year CS student, and next semester I'd like to write a research paper (it'd be my first) related to rust, static analysis or programming languages, or even all of them to some degree. Something about functional programming would work as well.

Any ideas of something interesting that I could research and write about?

view more: ‹ prev next ›

Rust

8252 readers
30 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS