Rust Lang

709 readers
1 users here now

Rules [Developing]

Observe our code of conduct

Constructive criticism only

No endless relitigation

No low-effort content

No memes or image macros

No NSFW Content

founded 1 year ago
MODERATORS
1
 
 

Welcome all Reddit refugees, rustaceans and everyone else. Let's keep it civil and check out the fediverse together!

2
2
This Week in Rust 553 (this-week-in-rust.org)
submitted 1 week ago by njaard to c/[email protected]
3
4
5
6
 
 

JFC. When will open source projects like @rustlang learn that putting toxic people like this in positions of ANY authority is unacceptable. https://github.com/marshallpierce/rust-base64/issues/213 . He's showing you who he is, and you're not listening.

7
8
6
Qualifying Rust without forking (ferrous-systems.com)
submitted 9 months ago by koka to c/[email protected]
9
10
11
29
submitted 9 months ago by koka to c/[email protected]
12
13
 
 

https://crates.io/crates/syslog-ng-common/0.7.0

The colleague, who added @rustlang support to #syslog_ng left many years ago. Syslog-ng #Rust support was last touched 7 years ago. Still, there are regular downloads. Just #searchengines or there are real users? Does it actually work?

14
15
16
 
 

I'm working on a cli for a service I've made that maintains a node edge graph (think neo4j type thing). I want to be able to display a graph in the terminal in a sort of ascii art text form kinda like git log -graph. I haven't found any third part libraries that can do that and am looking for help.

17
18
62
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]
19
20
 
 

From the release notes

Restore from-source serde_derive build on all platforms — eventually we'd like to use a first-class precompiled macro if such a thing becomes supported by cargo / crates.io

21
 
 

serde_derive now ships a precompiled binary. This made a lot of people angry. The crate maintainer finally locked the issue.

22
18
std::any::Any for slices? (sh.itjust.works)
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]
 
 

I recently ran into an issue where I wanted to use Any for slices. However, it only allows 'static types (based on what I read, this is because you get the same TypeId regardless of lifetimes).

I came up with this workaround which I think is safe:

use std::{
    any::{Any, TypeId},
    marker::PhantomData,
};

#[derive(Clone, Debug)]
pub struct AnySlice<'a> {
    tid: TypeId,
    len: usize,
    ptr: *const (),
    marker: PhantomData<&'a ()>,
}

impl<'a> AnySlice<'a> {
    pub fn from_slice(s: &'a [T]) -> Self {
        Self {
            len: s.len(),
            ptr: s.as_ptr() as *const (),
            tid: TypeId::of::(),
            marker: PhantomData,
        }
    }

    pub fn as_slice(&self) -> Option<&'a [T]> {
        if TypeId::of::() != self.tid {
            return None;
        }
        Some(unsafe { std::slice::from_raw_parts(self.ptr as *const T, self.len) })
    }

    pub fn is(&self) -> bool {
        TypeId::of::() == self.tid
    }
}

edit: Unfortunately it seems like Lemmy insists on mangling the code block. See the playground link below.

T: Any ensures T is also 'static. The lifetime is preserved with PhantomData. Here's a playground link with some simple tests and a mut version: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3116a404c28317c46dbba6ed6824c8a9

It seems to pass Miri, including the mut version (which requires a bit more care to ensure there can only be one mutable reference). Any problems with doing this?

23
16
New features on lib.rs (users.rust-lang.org)
submitted 10 months ago by [email protected] to c/[email protected]
 
 

cross-posted from: https://programming.dev/post/1825728

Lots of new features!

Thought I should share this with those who don't use users.rust-lang.org. Note: I'm not affiliated with lib.rs, I'm only reposting to lemmy.

24
20
This Week in Rust 508 (this-week-in-rust.org)
submitted 10 months ago by [email protected] to c/[email protected]
25
12
This Week in Rust 507 (this-week-in-rust.org)
submitted 10 months ago by [email protected] to c/[email protected]
view more: next ›