These are chat archives for rust-lang/rust

3rd
Feb 2018
Kelly Thomas Kline
@kellytk
Feb 03 2018 04:09
Is Ok(_) => (), the correct syntax for covering the case where only the Err branch of the match is significant?
Kelly Thomas Kline
@kellytk
Feb 03 2018 04:23
How can projects be configured to not default to #[warn(unused_variables)] being on for the debug build?
Andrey Lesnikov
@ozkriff
Feb 03 2018 04:24
I think if let Err(foo) = bar() { ..... } is better if you don't want to handle Ok branch anyway
Kelly Thomas Kline
@kellytk
Feb 03 2018 04:30
@ozkriff Where is match?
Kelly Thomas Kline
@kellytk
Feb 03 2018 04:39
Thanks @ozkriff. if let Err(error) = ... to handle solely error cases is pleasantly concise
Andrey Lesnikov
@ozkriff
Feb 03 2018 04:40

How can projects be configured to not default to #[warn(unused_variables)] being on for the debug build?

I'm not sure but the only thing I can come up with is running it not as cargo build but cargo rustc -- -A unused

Marek Janda
@mjanda
Feb 03 2018 05:46
@jaemk thank you
chtotut
@chtotut
Feb 03 2018 06:52

Hi all.

1) Who can explain why the commented line is not valid?
Why are the rules of type coercions is different for *mut and *const?
https://play.rust-lang.org/?gist=4be28f0e092abb94f073bc1e9149a010&version=nightly

2) Will memory deallocation for the b free all 8 bytes or only 4? Or does it depend on the system?
https://play.rust-lang.org/?gist=7c432745c4644711e76adfac945f734e&version=undefined

Peter Atashian
@retep998
Feb 03 2018 06:59
@chtotut For your second question, Rust defines that as undefined behavior and you should never do that. In practice, it depends on the system but the result can range from deallocating the entire thing because the allocator ignores the size when deallocating, to heap corruption causing sadness.
chtotut
@chtotut
Feb 03 2018 07:01
@retep998 thanks
CryptoPatrick
@cryptopatrick_twitter
Feb 03 2018 09:16
Hi! Is there a Rust style guide? Is any of these prefered: foo_bar, foobar, fooBar, FooBar?
I would say that "foo_bar" is the most common one for functions and FooBar is the one for types
CryptoPatrick
@cryptopatrick_twitter
Feb 03 2018 09:18
@ozkriff Great! Thanks!
red75prime
@red75prime
Feb 03 2018 09:18
foo_bar for functions and variables, FooBar for types and traits, FOOBAR for contstants
Kelly Thomas Kline
@kellytk
Feb 03 2018 09:31
@red75prime What about FOO_BAR?
Andrey Lesnikov
@ozkriff
Feb 03 2018 09:32
SCREAMING_SNAKE_CASE is used for consts and statics, see the link above :)
Kelly Thomas Kline
@kellytk
Feb 03 2018 09:33
Thanks
samoylovfp
@samoylovfp
Feb 03 2018 10:35

Hi! I'm trying to understand how modifiers in iron work. consider part of a handler:

    let mut r = Response::new();
    let data = include_str!("../www/index.html");
    Modifier::modify(data, &mut r);

I cant find where Modifier is implemented for &str or for Response

samoylovfp
@samoylovfp
Feb 03 2018 10:39
here it is implemented for tuples
Andrey Lesnikov
@ozkriff
Feb 03 2018 10:43
It accepts F, which has only one very broad requirement - ?Sized.
samoylovfp
@samoylovfp
Feb 03 2018 10:44
I see but I still cannot find actual implementation for Response
Denis Lisov
@tanriol
Feb 03 2018 10:47
For example, here
samoylovfp
@samoylovfp
Feb 03 2018 10:47
thanks! I tried to find it via docs, but unsuccessful
chtotut
@chtotut
Feb 03 2018 14:27
Hi again.
There is a question. Is it legal to create a box (with DST) like this?
https://play.rust-lang.org/?gist=3fac0b7b1688695956a5efe799b020df&version=nightly
If not, is it possible to create boxed DST (with custom memory alocation) or need define custom smart pointer like Box?
I mean, will the Box free the memory correctly?
Roman Proskuryakov
@kpp
Feb 03 2018 14:32
No it is not legal
Since the way Box allocates and releases memory is unspecified, the only valid pointer to pass to this function is the one taken from another Box via the Box::into_raw function.
And you will be able to Box::new(Handle{ field1: 42})
Roman Proskuryakov
@kpp
Feb 03 2018 14:38
and Box mem will be allocated with your unsafe fn alloc(size: usize) function
chtotut
@chtotut
Feb 03 2018 14:39
but it change allocator for other box... no?
Roman Proskuryakov
@kpp
Feb 03 2018 14:40
I guess it will
chtotut
@chtotut
Feb 03 2018 14:40
Is it possible to create valid Box from fat DST pointer?
Roman Proskuryakov
@kpp
Feb 03 2018 14:41
Do you want to create an arena and create Box<T> of some T allocated inside your arena?
chtotut
@chtotut
Feb 03 2018 14:50
I want to manually allocate memory on the heap (using allocator_api). Then create a box from the allocated memory, which will correctly free it.
Roman Proskuryakov
@kpp
Feb 03 2018 14:57
Why?
I gave you a link to rust-lang/rust#27779
Please read the thread. It is about DST types too
chtotut
@chtotut
Feb 03 2018 15:07
@kpp how to define DST struct (see code) with some length (defined only at run-time)
placement_in_syntax only for compile time (I could be wrong):
let x: Box<[u8]> = std::boxed::HEAP <- [0; 100];
Roman Proskuryakov
@kpp
Feb 03 2018 15:10
I'm 👎 to stabilizing Placer and BoxPlace as-is since the current interface cannot support DST at all, as mentioned above in #27779 (comment). The only way to get a DST via box x currently is via unsizing or converting from other types like Vec. This closes the potential extension of allowing box [x; dyn n].
If you don't want to wait the feature stabilize you may dig into compiler and cast some necromancy spells