These are chat archives for rust-lang/rust

14th
Dec 2016
xialvjun
@xialvjun
Dec 14 2016 06:15
What's Interior vs. Exterior Mutability?
Can I say the Interior Mutability is infact unsafe code block ?
Peter Atashian
@retep998
Dec 14 2016 06:15
no?
A type is said to have Interior mutability when its contents can be accessed mutably, even when you only have immutable access to the type itself
types such as Cell RefCell Mutex RwLock and the various atomics
xialvjun
@xialvjun
Dec 14 2016 06:17
Yeah, and I look into Arc source, found some unsafes.
Peter Atashian
@retep998
Dec 14 2016 06:17
Arc does not provide interior mutability
Alexander Ronald Altman
@pthariensflame
Dec 14 2016 06:18
It makes use of it, though, but not in the same places as unsafe.
Peter Atashian
@retep998
Dec 14 2016 06:18
It does use interior mutability to handle reference counting, but it does not provide interior mutability
Alexander Ronald Altman
@pthariensflame
Dec 14 2016 06:19
Exterior mutability is derived from mut. Interior mutability is derived from UnsafeCell. That's all there is too it.
Peter Atashian
@retep998
Dec 14 2016 06:19
of course, accessing the contents of an UnsafeCell does require unsafe
Alexander Ronald Altman
@pthariensflame
Dec 14 2016 06:19
*to
Peter Atashian
@retep998
Dec 14 2016 06:19
but abstractions like Cell and so on wrap that in a safe api by enforcing various restrictions on how you use it
@pthariensflame Gitter allows you to edit your messages
xialvjun
@xialvjun
Dec 14 2016 06:23
I'm not meaning using interior mutability is unsafe. I just mean we implement interior mutability by unsafe code block. And of cource, we can wrap it in a safe api.
xialvjun
@xialvjun
Dec 14 2016 11:05
match x {
    ref r => println!("Got a reference to {}", r),                                 // the same as ----------- let r = &x;    this is as expected.
    ref mut mr => println!("Got a mutable reference to {}", mr),    // the same as ------- let mr = &mut x;     this is unexpected, why it's not ---- let mut mr = &x;
    // and what can be -------------- let mut mr = &mut x;
}
Matanel Levi
@matanelevi
Dec 14 2016 21:31
Is it possible to cast a u32 to bool?
Aleksey Kladov
@matklad
Dec 14 2016 21:32
x != 0 should do the trick I guess
Matanel Levi
@matanelevi
Dec 14 2016 21:33
@matklad ok.. thanks :)
Matanel Levi
@matanelevi
Dec 14 2016 23:13
let answer_len = self.socket.read_u32::<BigEndian>().unwrap();
let mut answer_encoded = Vec::with_capacity(answer_len as usize);
self.socket.read_exact(answer_encoded.as_mut_slice());
For some reason, I get StringError("failed to fill whole buffer"
The other side use write_all to send the data
Someone knows why the error occurs?