Rust Programming

8386 readers
1 users here now

founded 5 years ago
MODERATORS
1
2
 
 

Are there some big projects/games that are released and made in bevy?

A lot of times tiny glade is mentioned, but I can not find a reliable source from the devs that it is made in bevy.

3
 
 

I've used Godot, which works great but I'm wondering if there are other ways.

Does anyone have experience using Qt with Rust and Qt Designer?

Are there any other drag and drop options that you think are viable?

4
20
submitted 3 weeks ago* (last edited 2 weeks ago) by tracyspcy@lemmy.ml to c/rust@lemmy.ml
5
31
New Rust stable version (blog.rust-lang.org)
submitted 3 weeks ago by Zenlix@lemm.ee to c/rust@lemmy.ml
6
 
 

An interesting video about actor programming in Rust.

7
 
 

Iced, a popular GUI Crate, used by system76 for their new DE, is getting default animation support in the development branch. The animations are based on the lilt crate. As far as I know the only missing part that needs to be done is, adding animations to the default widgets.

I assume in the next release it will be shipped with animation support.

I am so happy that this is coming and look forward to see animations in my gui applications.

8
 
 

cross-posted from: https://feddit.org/post/7326044

Inspired by Contex-Generic Programming, I made this macro, that allows you to write those generic implementations easily. This is kinda CGP, but simple and with better errors.

Ever repeat yourself implementing traits? Or wanted to easily swap out parts of your code, with (almost) no need to refactor? That is what this is for.

9
 
 

New Release 1.6.0 of Persy single file embedded storage is out

Persy is a single file transactional embedded storage, is scope is become a base of persistent databases implementations or for simple low level database to embed in application.

This is a new minor release 1.6.0 that include a simple feature that allow to create snapshots from the commit of a transaction, release post with all details here: https://persy.rs/posts/persy-1.6.html

10
11
 
 

This is what I've found:

In C and C++, two different operators are used for calling methods: you use . if you’re calling a method on the object directly and -> if you’re calling the method on a pointer to the object and need to dereference the pointer first. In other words, if object is a pointer, object->something() is similar to (*object).something().

What about Rust?

Rust doesn’t have an equivalent to the -> operator. Instead, Rust has what is called automatic referencing and dereferencing.

In other words, the following are the same:

p1.distance(&p2); (&p1).distance(&p2); Note: this automatic referencing behavior works because methods have a clear receiver-the type of self. Given the receiver and name of a method, Rust can figure out definitively whether the method is reading (&self), mutating (&mut self), or consuming (self).

I am not sureI understood the note correctly, what does it mean that there is a clear receiver? Also, doesn't Rust actually have an operator for dereferencing (*) as well?

12
13
 
 

axum is an ergonomic and modular web framework built with Tokio, Tower, and Hyper

14
 
 

It seems quite clear that rust users use hyper but few of them want to work on making it work for a C project like curl, and among existing curl users there is virtually no interest in hyper. The overlap in the Venn diagram of the two universes is not big enough.

15
 
 

Hello,

I have started learning Rust. I have only made a fibonaci series program so far but I would make more complex program as I progress in learning Rust :D

16
 
 

axum is a web application framework that focuses on ergonomics and modularity.

Hey! If you're using axum, I would be happy if you tried the first release candidate of the upcoming v0.8.0, and shared any feedback you have. That's all :)

17
18
 
 

I am trying to understand the std::process::Termination trait.

As I'm not really used to read libraries, I took this as a challenge to try understanding a bit more about how to read them as well.

I think trying to build a library would give me better understanding, but for now...

Termination is quite easy, from the trait page I can see that this trait has single method: report, which returns an ExitCode.

pub trait Termination {
    fn report(self) -> ExitCode;
}

But when I try to dig in further and i read the page related to ExitCode, it confuses me a bit.

ExitCode is a struct, therefore it behaves like a type with many fields which define the types contained in the struct.

I cannot really understand what's the point of this type.. I don't see any fields defined in the struct and this part confuses me a lot:

The standard library provides the canonical SUCCESS and FAILURE exit codes as well as From for ExitCode for constructing other arbitrary exit codes.

I even thought this meant it was an enum which had the SUCCESS, FAILURE etc as variants, but this does not seem the case.

Can you help me to understand how this specific structs work, what exactly does it do and how I should read library pages like this one?

19
22
submitted 2 months ago* (last edited 2 months ago) by aclarke@lemmy.world to c/rust@lemmy.ml
 
 

I was recently furloughed from work, so in between job applications, I decided to polish off Sonarr support in my Managarr TUI. Thus, I'm very proud to announce the beta release of Managarr with Sonarr support!

TL;DR: Managarr is a TUI and CLI for managing your Servarr instances. As of now, it now supports both Radarr and Sonarr and all the features that are available in the UI are also available in the CLI for scripting and additional automation.

The new version has the following features:

  • Wider platform support (Windows, Mac, Linux, x86_64 and arm64)
  • View your library, downloads, blocklist, episodes
  • View details of a specific series, or episode including description, history, downloaded file info, or the credits
  • View your host and security configs from the CLI to programmatically fetch the API token, among other settings
  • Search your library
  • Add series to your library
  • Delete series, downloads, indexers, root folders, and episode files
  • Trigger automatic searches for series, seasons, or episodes
  • Trigger refresh and disk scan for series and downloads
  • Manually search for series, seasons, or episodes
  • Edit your series and indexers
  • Manage your tags
  • Manage your root folders
  • Manage your blocklist
  • View and browse logs, tasks, events queues, and updates
  • Manually trigger scheduled tasks
  • Manually trigger scheduled tasks
  • And more!

Here's some screenshots of the Sonarr tab:

Thanks to everyone's feedback when I first posted the alpha release here, this version sports a handful of additional performance improvements and platform support.

This is now technically in beta, so if anyone encounters any issues, please let me know!

20
21
22
 
 

cross-posted from: https://lemmy.world/post/22673996

This mod is written in an unconventional way: it is written in Rust. The Rust code is here. It uses JNI and JVMTI to interact with Java objects. The only Java code in this mod is for loading the compiled native binary into memory.

23
 
 

Hey there! I'm starting my journey to the learning of Rust. I have been coding only with Python for 6 years now and last year, I had to code in JavaScript using VueJS for my job (I never workedeon frontend).

Now, I have a personal project idea which I'd like to create. I could do it in Python but I want to learn Rust. I've looked up on the Internet but may be some answers are too old or someone here can point me to something I haven't seen yet.

What do you recommand for webdev? I guess I need to code the back in Rust and use a JavaScript framework for the front. My backend will be for a REST API (my app will need to manage users and organisations).

Bonus question if you can recommend a BDD framework. I think there is something named Cucumber. Is it good?

Thanks a lot ♥️🦀

24
11
submitted 2 months ago* (last edited 2 months ago) by raldone01@lemmy.world to c/rust@lemmy.ml
 
 

Hello,

I was playing around with rust and wondered if I could use const generics for toggling debug code on and off to avoid any runtime cost while still being able to toggle the DEBUG flag during runtime. I came up with a nifty solution that requires a single dynamic dispatch which many programs have anyways. It works by rewriting the vtable. It's a zero cost bool!

Is this technique worth it?

Probably not.

It's funny though.

Repo: https://github.com/raldone01/runtime_const_generics_rs/tree/v1.0.0

Full source code below:

use std::mem::transmute;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;

use replace_with::replace_with_or_abort;

trait GameObject {
  fn run(&mut self);
  fn set_debug(&mut self, flag: bool) -> &mut dyn GameObject;
}

trait GameObjectBoxExt {
  fn set_debug(self: Box<Self>, flag: bool) -> Box<dyn GameObject>;
}

impl GameObjectBoxExt for dyn GameObject {
  fn set_debug(self: Box<Self>, flag: bool) -> Box<dyn GameObject> {
    unsafe {
      let selv = Box::into_raw(self);
      let selv = (&mut *selv).set_debug(flag);
      return Box::from_raw(selv);
    }
  }
}

static ID_CNT: AtomicU32 = AtomicU32::new(0);

struct Node3D<const DEBUG: bool = false> {
  id: u32,
  cnt: u32,
}

impl Node3D {
  const TYPE_NAME: &str = "Node3D";
  fn new() -> Self {
    let id = ID_CNT.fetch_add(1, Ordering::Relaxed);
    let selv = Self { id, cnt: 0 };
    return selv;
  }
}

impl<const DEBUG: bool> GameObject for Node3D<DEBUG> {
  fn run(&mut self) {
    println!("Hello {} from {}@{}!", self.cnt, Node3D::TYPE_NAME, self.id);
    if DEBUG {
      println!("Debug {} from {}@{}!", self.cnt, Node3D::TYPE_NAME, self.id);
    }
    self.cnt += 1;
  }

  fn set_debug(&mut self, flag: bool) -> &mut dyn GameObject {
    unsafe {
      match flag {
        true => transmute::<_, &mut Node3D<true>>(self) as &mut dyn GameObject,
        false => transmute::<_, &mut Node3D<false>>(self) as &mut dyn GameObject,
      }
    }
  }
}

struct Node2D<const DEBUG: bool = false> {
  id: u32,
  cnt: u32,
}

impl Node2D {
  const TYPE_NAME: &str = "Node2D";
  fn new() -> Self {
    let id = ID_CNT.fetch_add(1, Ordering::Relaxed);
    let selv = Self { id, cnt: 0 };
    return selv;
  }
}

impl<const DEBUG: bool> GameObject for Node2D<DEBUG> {
  fn run(&mut self) {
    println!("Hello {} from {}@{}!", self.cnt, Node2D::TYPE_NAME, self.id);
    if DEBUG {
      println!("Debug {} from {}@{}!", self.cnt, Node2D::TYPE_NAME, self.id);
    }
    self.cnt += 1;
  }

  fn set_debug(&mut self, flag: bool) -> &mut dyn GameObject {
    unsafe {
      match flag {
        true => transmute::<_, &mut Node2D<true>>(self) as &mut dyn GameObject,
        false => transmute::<_, &mut Node2D<false>>(self) as &mut dyn GameObject,
      }
    }
  }
}

fn main() {
  let mut objects = Vec::new();
  for _ in 0..10 {
    objects.push(Box::new(Node3D::new()) as Box<dyn GameObject>);
    objects.push(Box::new(Node2D::new()) as Box<dyn GameObject>);
  }

  for o in 0..3 {
    for (i, object) in objects.iter_mut().enumerate() {
      let debug = (o + i) % 2 == 0;
      replace_with_or_abort(object, |object| object.set_debug(debug));
      object.run();
    }
  }
}

Note:

If anyone gets the following to work without unsafe, maybe by using the replace_with crate I would be very happy:

impl GameObjectBoxExt for dyn GameObject {
  fn set_debug(self: Box<Self>, flag: bool) -> Box<dyn GameObject> {
    unsafe {
      let selv = Box::into_raw(self);
      let selv = (&mut *selv).set_debug(flag);
      return Box::from_raw(selv);
    }
  }

I am curious to hear your thoughts.

25
 
 

In python, when you install stuff with pip, it is recommended to use a venv, to avoid breaking dependencies for a program when uninstalling another one, or when two programs need two different versions of the same dependence.

I was wondering if with Rust is the same, or if Cargo manages it all on its own (kind of like apt does), and I shouldn't care about it.

Also since I know Linux kernel is using some Rust, isn't there a risk of breaking my system if I uninstall a program that need some deps that the system itsel needs?

view more: next ›