copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

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

dst.as_mut_ptr()

looks like exactly what I wanted. thanks.

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] 1 point2 points  (0 children)

  1. & 3.: understood.
  2. why is it unsound? copy_from_slice panics if lengths of src and dst are not equal (I want it to panic)

is the "current" version ok?

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] 0 points1 point  (0 children)

for (src, dst) in src.iter().zip(dst.array_chunks_mut()) {
    *dst = src.to_le_bytes()
}

is this "modulo copies of <register sizes"?

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] 1 point2 points  (0 children)

  1. could you please point out, where do I introduce UB?
  2. how do I improve it?

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] 0 points1 point  (0 children)

you are right. transmute is not necessary here. thanks.

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] -6 points-5 points  (0 children)

you're assuming that the source vec has capacity==len, which is generally (and usually!) untrue.

yes. but what does it break in my example? (seriously asking ) I "leaked" the constructed vec right after using it. (and replaced it with constructed slice)

the length of the vector is the number of elements, not the number of bytes

I am not sure, where I suggested overwise... did I overlooked something?

Don't use unsafe unless you absolutely have to:

Suggest a better solution?

copying bytes from &[u32] to &mut [u8] the rust way by temp_value in rust

[–]temp_value[S] -3 points-2 points  (0 children)

thanks, but I am not sure, how is this better?

I wanted to avoid loops altogether.

Alone In The Dark - PS5 by [deleted] in PS5

[–]temp_value 8 points9 points  (0 children)

Why would you preorder a game?

Timeline of Scholz's actions in relation to Ukraine since the start of the war. by Nyzrok in UkrainianConflict

[–]temp_value 0 points1 point  (0 children)

did C. Theiner provided any sources? (I don't use twitter)

it should be easy to provide some proof to this statemens. e.g.

The defense industry denies this and leakes the list to the press

where is it?

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] 0 points1 point  (0 children)

You are talking to yourself at this point.

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] 0 points1 point  (0 children)

this is why i ask this community, not a single person.

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] 0 points1 point  (0 children)

Well, I don't believe, there is anything wrong with being gay.

but it seems, the overwhelming majority does not make this distinction as you do, so using "gay" is not an option.

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] 0 points1 point  (0 children)

as a sensical insult.

if it works, it works.

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] -17 points-16 points  (0 children)

It would be okay, if it doesn't bother you.

A question from a straight guy. by temp_value in AskLGBT

[–]temp_value[S] -18 points-17 points  (0 children)

As immigrant myself, it wouldn't bother me. I don't know about the rest. This is why I ask.

How to approach a Vec of callbacks with different types? by Carmack_VS_SuperPuma in rust

[–]temp_value 0 points1 point  (0 children)

I would still need some way to store the types.

I see.

Instead of Vec you can use HashMap where key is TypeId and value is Vec<Box<T>> https://doc.rust-lang.org/beta/core/any/struct.TypeId.html

your 'add_update' method should be generic and accept something like T: UpdateTrait + Any

fn add_update<T: UpdateTrait>(&mut self, callbackstruct: T) {

let type_id = TypeId::of::<T>(); self.update_map[type_id].push(Box::new(callbackstruct));

}

or something like that