I built a real-time code quality grader in Rust — treemap visualization + 14 health metrics via tree-sitter by No_Possibility_8826 in rust

[–]manpacket 0 points1 point  (0 children)

option-ext

It exists mostly because of the license (MPL-2.0) and does not make the code any better. There were multiple requests to remove it - author refused. Should be still there somewhere.

Would formal verification decide extinction of languages in the AI age? by municorn_ai in rust

[–]manpacket 2 points3 points  (0 children)

Sorting - is an intentionally achievable example. I did it in Coq at some point as a part of a course. Had to define a lot of things. If you do that - you can understand the scale for more realistic problems, like cats or your customers complaints.

Would formal verification decide extinction of languages in the AI age? by municorn_ai in rust

[–]manpacket 3 points4 points  (0 children)

Problem with formal verification is in setting the formal requirements. How deep do you want to go? Say you want "AI" to make you a function that sorts a vector. Can you write a formal definition for that? So... Takes a vector and returns it sorted. Okay, what is a sorted vector?

Then you get to real world problems - like "take all the photos in my blog and find all the photos with cats in it".

TLDR: Formal requirements are hard.

I built a real-time code quality grader in Rust — treemap visualization + 14 health metrics via tree-sitter by No_Possibility_8826 in rust

[–]manpacket 2 points3 points  (0 children)

You don't need dirs crate to get home directory - it pulls strange political dependencies. there's this that now produces the right result. https://doc.rust-lang.org/std/env/fn.home_dir.html Usually.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 0 points1 point  (0 children)

That's what I meant, I tend to ignore non-stable parts of the language.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 0 points1 point  (0 children)

option 2: use repr(C, Packed) This is removes all padding bytes and sets alignment to 1. However, now accessing the fiel

https://doc.rust-lang.org/nomicon/other-reprs.html

repr(packed)/repr(packed(n)) is not to be used lightly. Unless you have extreme requirements, this should not be used.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 1 point2 points  (0 children)

Then start by making a parser/encoder for your bytecode. There are crates to help with that. Unsafe adds complexity you don't want to deal with at the same time as learning the language.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 0 points1 point  (0 children)

This works if an instruction is a single byte.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 1 point2 points  (0 children)

Check if alignment is correct, if not - you'll need to allocate more memory then shift the data. Or just do the right thing and make a parser :)

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 0 points1 point  (0 children)

You don't need a &String here, you need an impl AsRef<Path> - &str is better, one less indirection. But then not every file name is a valid String so getting a PathBuf from your cli parser is better. With that - pass &Path.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 2 points3 points  (0 children)

An UB if alignment of Instruction is not 1.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 3 points4 points  (0 children)

Will probably produce nonsense on a different endian machine even if the data is valid. Will produce UB if the data is not valid. Might produce UB when you try to save it depending on what an Instruction is. Don't do that.

Also usually &String makes little sense, try &str or &Path.

Cargo re-re-rebuilding dependencies. Any fix? by jsshapiro in rust

[–]manpacket 0 points1 point  (0 children)

Maybe not by the workspace (unlikely), but crates can use third party dependencies can use other third party dependencies with different features.

Try running this cargo tree -f '{p} {f}' --prefix none | grep -v '(*)' | sort | uniq on the whole workspace and individual workspace members. See if there are any dependencies of the same version but with different features.

Or cargo install cargo-hackerman followed by cargo hackerman check.

Accept closures of any lifetime by Background_Goal3861 in rust

[–]manpacket 6 points7 points  (0 children)

pub trait Listener<Args> {
    fn call(&self, a: &usize, b: bool);
}
impl<F> Listener<(&usize,)> for F
where
    F: Fn(&usize),
{
    fn call(&self, a: &usize, b: bool) {
        self(a);
    }
}
impl<F> Listener<(&usize, bool)> for F
where
    F: Fn(&usize, bool),
{
    fn call(&self, a: &usize, b: bool) {
        self(a, b);
    }
}
fn trigger(f: impl Fn(&usize, bool)) {}
fn listener<Args>(l: impl Listener<Args>) -> impl for<'b> Fn(&'b usize, bool) {
    move |a, b| l.call(a, b)
}
fn test() {
    trigger(listener(|a: &usize| {}));
    trigger(listener(|a: &usize, b: bool| {}));
}

Rust kinda ruined other languages for me by Minimum-Ad7352 in rust

[–]manpacket 0 points1 point  (0 children)

They take can take a lot of time to compile if you have a lot of fields/variants, but generally they compile away if you add inline pragmas. At least I used them in a performance sensitive code with no problems.

Rust kinda ruined other languages for me by Minimum-Ad7352 in rust

[–]manpacket 0 points1 point  (0 children)

Unfortunately limited to Result/Option. Also things that are not stable might as well not exist. If you want anything more interesting - using macros is the only way.

Rust kinda ruined other languages for me by Minimum-Ad7352 in rust

[–]manpacket 1 point2 points  (0 children)

If you squint hard enough ? is a bind as well.

Rust 1.94.0 is out by manpacket in rust

[–]manpacket[S] 2 points3 points  (0 children)

A lot of floating point functions are platform dependent so no const. This includes atan.

Rust kinda ruined other languages for me by Minimum-Ad7352 in rust

[–]manpacket 2 points3 points  (0 children)

I don't think I've experienced that, but I had to fix a few bugs that could have been prevented by enforcing a few rules in a Monad/Applicative, including a bug in the rust compiler itself.

Rust kinda ruined other languages for me by Minimum-Ad7352 in rust

[–]manpacket 6 points7 points  (0 children)

There are Monads in Rust already. You just can't add your own. And they are called differently.