Rust Programming

8414 readers
108 users here now

founded 5 years ago
MODERATORS
101
 
 

I am new to Rust, and have always been interested in how games were made. But man I've got to say that just ready the bevy book has been pretty fun. I am looking at all the examples in the repo. I wanna here others perspective on bevy, or Rust game development in general!

crossposted from: https://programming.dev/post/8881051

102
103
104
3
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

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

Live coding Matrix in Rust #owncast #streaming #coding #rust #matrix

Find Andy’s previous recordings at: https://diode.zone/a/andybalaam/video-channels

105
 
 

This library is responsible for federation in Lemmy, and can also be used by other Rust projects.

106
107
108
9
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

Hi! Mles (Modern Lightweight channEl Service) protocol with Rust-based reference implementation is on the path to upgrade to v2. The new version will be simpler and more secure. In case interested how to make the protocol v2 draft even better, please join discussion and comment on [email protected]. Thanks!

109
 
 

I've seen a few but I can't decide which protocol to use yet. I'm working on a DHT pet project and I'd like to avoid making it rely on any relay servers.

Thanks in advance for any pointers!

110
 
 

Ed: solved with the help of the async_stream crate.

I'm struggling with the borrow checker!

My problem: I'm using actix-web and rusqlite. I want to return an unlimited number of records from an rusqlite query, and actix provides a Stream trait for that kind of thing. You just impl the trait and return your records from a poll_next() fn.

On the rusqlite side, there's this query_map that returns an iterator of records from a query. All I have to do is smush these two features together.

So the plan is to put the iterator returned by query_map into a struct that impls Stream. Problem is the lifetime of a var used by query_map. How to make the var have the same lifetime as the iterator??

So here's the code:

pub struct ZkNoteStream<'a, T> {
  rec_iter: Box<dyn Iterator<Item = T> + 'a>,
}

// impl of Stream just calls next() on the iterator.  This compiles fine.
impl<'a> Stream for ZkNoteStream<'a, serde_json::Value> {
  type Item = serde_json::Value;

  fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
    Poll::Ready(self.rec_iter.next())
  }
}

// init function to set up the ZkNoteStream.
impl<'a> ZkNoteStream<'a, Result<ZkListNote, rusqlite::Error>> {
  pub fn init(
    conn: &'a Connection,
    user: i64,
    search: &ZkNoteSearch,
  ) -> Result<Self, Box<dyn Error>> {
    let (sql, args) = build_sql(&conn, user, search.clone())?;

    let sysid = user_id(&conn, "system")?;
    let mut pstmt = conn.prepare(sql.as_str())?;

    // Here's the problem!  Borrowing pstmt.
    let rec_iter = pstmt.query_map(rusqlite::params_from_iter(args.iter()), move |row| {
      let id = row.get(0)?;
      let sysids = get_sysids(&conn, sysid, id)?;
      Ok(ZkListNote {
        id: id,
        title: row.get(1)?,
        is_file: {
          let wat: Option<i64> = row.get(2)?;
          wat.is_some()
        },
        user: row.get(3)?,
        createdate: row.get(4)?,
        changeddate: row.get(5)?,
        sysids: sysids,
      })
    })?;

    Ok(ZkNoteStream::<Result<ZkListNote, rusqlite::Error>> {
      rec_iter: Box::new(rec_iter),
    })
  }
}

And here's the error:

error[E0515]: cannot return value referencing local variable `pstmt`
   --> server-lib/src/search.rs:170:5
    |
153 |       let rec_iter = pstmt.query_map(rusqlite::params_from_iter(args.iter()), move |row| {
    |                      ----- `pstmt` is borrowed here
...
170 | /     Ok(ZkNoteStream::<Result<ZkListNote, rusqlite::Error>> {
171 | |       rec_iter: Box::new(rec_iter),
172 | |     })
    | |______^ returns a value referencing data owned by the current function

So basically it boils down to pstmt getting borrowed in the query_map call. It needs to have the same lifetime as the closure. How do I ensure that?

111
22
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

UPDATE: I found this issue explaining the relicensing of rust game engine Bevy to MIT + Apache 2.0 dual. Tldr: A lot of rust projects are MIT/Apache 2.0 so using those licenses is good for interoperability and upstreaming. MIT is known and trusted and had great success in projects like Godot.

ORIGINAL POST:

RedoxOS, uutils, zoxide, eza, ripgrep, fd, iced, orbtk,...

It really stands out considering that in FOSS software the GPL or at least the LGPL for toolkits is the most popular license

Most of the programs I listed are replacements for stuff we have in the Linux ecosystem, which are all licensed under the (L)GPL:

uutils, zoxide, eza, ripgrep, fd -> GNU coreutils (GPL)

iced, orbtk -> GTK, QT (LGPL)

RedoxOS -> Linux kernel, most desktop environments like GNOME, KDE etc. all licensed GPL as much as possible

112
 
 

I find that a lot of libraries tend to be Linux-focused and generally kind of ugly on Windows, so what do you use when you want to make something that looks nice and performs well on Windows?

The best looking ones I've seen were web frontends like in Tauri. A runner up would maybe be iced-rs. Which is a shame because I really wanted to use relm or fltk-rs but it looks like I'd almost have to use the web renderer to get "sleek, sexy" GUIs...

113
 
 

We are starting a new meetup group for the Rhein-Neckar-Region in Heidelberg, Germany.

The first event will take place on December 19 at the University's Mathematikon.

The twist is that we're beginning with a dual-topic meetup: Nix & Rust.

As there is some overlap between the two communities and we couldn't decide for which of the two we'd rather organize a meetup, we went for both in one.

The meetup is organized through the regional Mobilizon instance: https://rheinneckar.events/events/298e520c-89ca-4754-96f8-e252b96b7a46

Please sign up if you plan on attending so we can make sure there is enough space for all participants. Also feel free to drop an email at [email protected] or a Mastodon message at https://rheinneckar.social/@NixRust if you would like to become a speaker for the meetup, be it with a NixOS or Rust topic, or a combination of both!

The current (tentative) schedule:

  • 18:30 - Open Doors

  • 19:00 - Greeting

  • 19:05 - An Introduction to Nix

  • 19:30 - Second Talk (Rust related)

  • 20:00 - Networking and get together

114
115
 
 

This is the new release of Axum, the first to use the also newly-released hyper 1.0.

116
 
 

I'm a complete beginner in programming with no prior experience, and I want a tutor/mentor to learn Rust for software(GUI, games, software in general) development and, eventually, kernel development(microkernels, IPC, specifically). I pay, of course. (Also, another note, I dislike UNIX (philosophy wise), so I would be looking to get experience in non-UNIX kernel development but also learn UNIX stuff as well.) Furthermore, to note, is I'm interested in game development.

I have a document from my previous tutor in this outlining the stuff I am keen to learn, practically a syllabus, so if you want to see it dm me :3.

117
118
54
Bevy 0.12 (bevyengine.org)
submitted 1 year ago by [email protected] to c/[email protected]
119
 
 

Interesting stack

120
121
 
 

In practical perspectives, I'm mostly concerned about computer resources usage; I have computer resources constraints. So using Rust would benefit on that. But it is for a Web application backend. So, is it worth it having to learn Rust + Tokio + Axum, ... in this specific situation? Also, that this is mostly for initially prototyping an application. Also considering if I add developers in the future, they would most likely not be familiar with Rust, but with more popular frameworks such as Node.

122
 
 

A nice and long read about the history of async Rust. Gives a nice set of reasons for why it is as it is now.

I would still hope though that Rust would be more bold when it comes to making breaking changes that improve the language in the future. Given that the edition system was made exactly for that.

123
124
 
 

I'm curious as to how the hashbrown crate can have up to 2x performance on certain operations, even though it looks like the standard library's HashMap is just a wrapper for hashbrown.

I understand that a wrapper could add a small overhead, but 50% of the original performance is a bit silly, especially considering all of the functions in the wrapper are #[inline], so there should be no overhead in calling most functions.

Does anyone know the reason for this?

125
view more: ‹ prev next ›