These are chat archives for rust-lang/rust

19th
May 2018
Farzeen
@thefzsalam
May 19 2018 02:20 UTC
what does *mut _ mean?
For example, let state_ptr: *mut c_void = &mut state as *mut _ as *mut c_void;
Denis Lisov
@tanriol
May 19 2018 05:15 UTC
@thefzsalam This converts the unique reference first to a raw mutable pointer to the same type, and then to a mutable void pointer. There's no direct conversion, AFAIK.
Farzeen
@thefzsalam
May 19 2018 05:15 UTC
Oh..
thanks @tanriol :)
Farzeen
@thefzsalam
May 19 2018 11:32 UTC
what does _ mean in this context? What is the type referred to as 'same type' here?
static mut PRIV: FooClassPrivate = FooClassPrivate {
    parent_class: 0 as *const _,
};
Michal 'vorner' Vaner
@vorner
May 19 2018 11:36 UTC
Basically, _ as part of type means you say „Figure this by yourself so the whole thing makes sense“ to the compiler. It looks like parent_class is some type of pointer to something, so for this to make sense, the same something needs to be substitued there.
However, I think using https://doc.rust-lang.org/std/ptr/fn.null.html would have been more idiomatic here
Restioson
@Restioson
May 19 2018 11:50 UTC
is ptr::write_bytes volatile?
is there a reason null/null_mut aren't for T: ?Sized?
Restioson
@Restioson
May 19 2018 12:18 UTC
Also in GlobalAlloc, the arg for realloc which is Layout -- is this the old layout?
Michal 'vorner' Vaner
@vorner
May 19 2018 12:22 UTC
I don't think rust has any notion of volatile. What should that mean?
And there's a reason for not having !Sized. There's no such thing as a raw pointer to unsized types, because these are fat pointers and aren't compatible with machine/C notion of what a pointer is.
Andrey Lesnikov
@ozkriff
May 19 2018 12:25 UTC

I don't think rust has any notion of volatile. What should that mean?

Hmmm - but there's https://doc.rust-lang.org/std/ptr/fn.read_volatile.html

Rust does not currently have a rigorously and formally defined memory model, so the precise semantics of what "volatile" means here is subject to change over time. That being said, the semantics will almost always end up pretty similar to C11's definition of volatile.

The compiler shouldn't change the relative order or number of volatile memory operations. However, volatile memory operations on zero-sized types (e.g. if a zero-sized type is passed to read_volatile) are no-ops and may be ignored.

Restioson
@Restioson
May 19 2018 13:05 UTC
i don't want it to be optimised out
Andrey Lesnikov
@ozkriff
May 19 2018 13:08 UTC

is there a reason null/null_mut aren't for T: ?Sized?

@Restioson https://users.rust-lang.org/t/is-there-a-reason-that-std-ptr-requires-t-sized/10396/3

I think the reason is that unsized pointers are usually (always?) “fat” pointers, with a second word that can’t be generalized. e.g. *const [T] and *const str have a length, and a trait object like *const Iterator has a vtable pointer.
Denis Lisov
@tanriol
May 19 2018 13:21 UTC
@Restioson Are you creating your own synchronization primitives?
Restioson
@Restioson
May 19 2018 16:57 UTC
@tanriol no, i am implementing heap
oh, im using the write bytes to zero bytes in a page of memory so i dont have to push 2mib potentially of 0 to my stack
Kelly Thomas Kline
@kellytk
May 19 2018 21:23 UTC
Which terms would I search for to find a comprehensive list of available feature flags like #![feature(nll)]?
Kelly Thomas Kline
@kellytk
May 19 2018 22:20 UTC
Thanks. Do you think it would be beneficial to add a link to those resources in some area of documentation for Rust users that are interested in testing new features and/or at https://doc.rust-lang.org/book/second-edition/appendix-06-newest-features.html?
Matthias Berndt
@mberndt123
May 19 2018 23:51 UTC
Hi. I want to write a little webapp for my OpenWrt wireless router. Naturally that box doesn't have a lot of RAM, so I'm looking for a very lean web framework. Any suggestions?