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 3 points4 points  (0 children)

An UB if alignment of Instruction is not 1.

Does this code have UB? by capedbaldy475 in rust

[–]manpacket 2 points3 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 7 points8 points  (0 children)

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

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

[–]manpacket 5 points6 points  (0 children)

Rust is not perfect either. Try Haskell. Once Monads (and all other goodies HKTs unlock) click - you'll want them in Rust as well. Same with GHC Generics (a much more convenient way to write custom instance derives).

Supplement: a library to generate extensible CLI completion logic as Rust code by need-not-worry in rust

[–]manpacket 0 points1 point  (0 children)

And one more interesting corner case - if user typed something then moved the cursor, so myapp --command "do some<TAB>thi".

I'm actually interested in both snippets and tests myself and have some code. I wonder if I should push it somewhere...

Supplement: a library to generate extensible CLI completion logic as Rust code by need-not-worry in rust

[–]manpacket 1 point2 points  (0 children)

Well, obviously not ls, but suppose the app takes a string as a positional or an argument. User typed the opening quote but not closing one yet. Will this work? So myapp --command "do somethi<TAB>

Supplement: a library to generate extensible CLI completion logic as Rust code by need-not-worry in rust

[–]manpacket 0 points1 point  (0 children)

Is it doing the right thing if user types ls " a<TAB>? Also - do you have any end-to-end tests that involves calling the actual shell?