Rust Lang

!rustlang

@lemmyrs.org
Create post
Async Rust Is A Bad Language

Async Rust Is A Bad Language

Open link in next tab

Async Rust Is A Bad Language

https://bitbashing.io/async-rust.html

Yet another programming blog. Thoughts on software and related misadventures.

Async Rust Is A Bad Language
Looking for graph tui

Looking for graph tui

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.

Change in Guidance on Committing Lockfiles

Change in Guidance on Committing Lockfiles

Open link in next tab

Change in Guidance on Committing Lockfiles | Rust Blog

https://blog.rust-lang.org/2023/08/29/committing-lockfiles.html

Empowering everyone to build reliable and efficient software.

Change in Guidance on Committing Lockfiles | Rust Blog
Transitioning /r/rust to the Threadiverse

Transitioning /r/rust to the Threadiverse

Open link in next tab

Transitioning /r/rust to the Threadiverse

https://blog.erlend.sh/transitioning-r-rust-to-the-threadiverse

Three months ago I submitted a post to the Rust sub-reddit called 'Building a better /r/rust together'. It quickly rose to the top and ga...

Transitioning /r/rust to the Threadiverse
Serde: from-source `serde_derive` restored on all platforms

Serde: from-source `serde_derive` restored on all platforms

Open link in next tab

Release v1.0.184 · serde-rs/serde

https://github.com/serde-rs/serde/releases/tag/v1.0.184

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

Release v1.0.184 · serde-rs/serde
Precompiled binary removed from serde in v1.0.184

Precompiled binary removed from serde in v1.0.184

Open link in next tab

Release v1.0.184 · serde-rs/serde

https://github.com/serde-rs/serde/releases/tag/v1.0.184

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

Release v1.0.184 · serde-rs/serde
Potential shitstorm brewing over ubiquitous serde crate

Potential shitstorm brewing over ubiquitous serde crate

Open link in next tab

using serde_derive without precompiled binary · Issue #2538 · serde-rs/serde

https://github.com/serde-rs/serde/issues/2538

I'm working on packaging serde for Fedora Linux, and I noticed that recent versions of serde_derive ship a precompiled binary now. This is problematic for us, since we cannot, under no circumstance...

using serde_derive without precompiled binary · Issue #2538 · serde-rs/serde
std::any::Any for slices?

std::any::Any for slices?

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?

New features on lib.rs

New features on lib.rs

Open link in next tab

New features on lib.rs

https://users.rust-lang.org/t/new-features-on-lib-rs/98560

I've implemented a few new things on lib.rs recently! New features page It lists all cargo features that a crate supports. It includes comments from Cargo.toml, neatly formatted as markdown, so you can learn what the features do. Since comments on features are rare, I also search crate's source code for uses of cfg(feature = "…") to give a hint what functions or types are affected by the feature. Cargo has this quirk that all optional dependencies implicitly create features, unless you use a ...

This Week in Rust 508

This Week in Rust 508

Open link in next tab

This Week in Rust 508 · This Week in Rust

https://this-week-in-rust.org/blog/2023/08/16/this-week-in-rust-508/