These are chat archives for rust-lang/rust

6th
Feb 2018
Kelly Thomas Kline
@kellytk
Feb 06 2018 01:08
Why is the syntax at https://play.integer32.com/?gist=09196c52a045378c46baffef91f8e5e8&version=stable incorrect and how is the type correctly declared?
@kellytk ^
Kelly Thomas Kline
@kellytk
Feb 06 2018 01:15
Thanks @kinggoesgaming
Hunar Roop Kahlon
@kinggoesgaming
Feb 06 2018 01:59
np :)
Kelly Thomas Kline
@kellytk
Feb 06 2018 03:02
Implementing an RwLock static is adding .read().unwrap() to call sites to the static. How could I redesign the static's struct and its API to implement the RwLock code internally? I would prefer to find a way to use RwLock for a struct, but still use the struct directly without the indirection through RwLock each time
Kelly Thomas Kline
@kellytk
Feb 06 2018 09:44
In attempting to use a macro from a mod elsewhere in the project, why is the error on line 7 at https://play.integer32.com/?gist=ba330185b2c18e7f17bc84c9db9f1de7&version=stable generated?
Denis Lisov
@tanriol
Feb 06 2018 09:45
@kellytk The macro_rules! macros do not use fully-qualified paths, IIRC, just names.
Kelly Thomas Kline
@kellytk
Feb 06 2018 09:46
What is the solution @tanriol?
Denis Lisov
@tanriol
Feb 06 2018 09:49
Or are you intentionally testing the use_extern_macros feature?
Kelly Thomas Kline
@kellytk
Feb 06 2018 09:49
I'm attempting to :-)
Denis Lisov
@tanriol
Feb 06 2018 09:56
Sorry, then no idea :-)
Jacob Flores
@flores-jacob
Feb 06 2018 11:02
Hi, do we have a way to check if an entire string (&str) object is in uppercase? I'm trying to use is_ascii_uppercase(), but I'm getting the error use of unstable library feature 'ascii_ctype'
Denis Lisov
@tanriol
Feb 06 2018 11:05
Something like string.chars().all(char::is_uppercase)
Jacob Flores
@flores-jacob
Feb 06 2018 11:08
Thanks! That works!
Jacob Flores
@flores-jacob
Feb 06 2018 13:50
For clarification to avoid tripping others up, I ended up using mystring.chars().all(|c| c.is_uppercase())
Kelly Thomas Kline
@kellytk
Feb 06 2018 15:12
Why @flores-jacob?
Jacob Flores
@flores-jacob
Feb 06 2018 15:14
Hi @kellytk . What do you mean?
Casey Allred
@sbditto85
Feb 06 2018 15:32
@flores-jacob I think that @kellytk was asking why the lambda instead of just doing "string".chars().all(char::is_uppercase);
Jacob Flores
@flores-jacob
Feb 06 2018 15:35
@sbditto85 I haven't gotten to the part of the book that handled lambdas yet.
I put in the clarification since I did try string.chars().all(char::is_uppercase) as suggested earlier, but it won't allow my code to compile
I figured that I might as well put in what worked for me, to avoid tripping up anyone who might be reading the conversation
Casey Allred
@sbditto85
Feb 06 2018 15:36
hummm ...i just did it to make sure it would and it worked for me ... shrug i'm a newb
Jacob Flores
@flores-jacob
Feb 06 2018 15:36
Yeah
I am :D
Casey Allred
@sbditto85
Feb 06 2018 15:37
the litteral line i put in a main.rs was println!("is upper => {}", "string".chars().all(char::is_uppercase)); and it compiled and put out "is upper => false"
println!("is upper => {}", "STRING".chars().all(char::is_uppercase)); puts out "is upper => true"
Jacob Flores
@flores-jacob
Feb 06 2018 15:41
I was doing some stuff for exercism.io. Here's the error I was getting ^^^ the traitstd::ops::FnMut<(char,)>is not implemented forbool``
Here's how I used it:
    let exclamation: bool = stripped_message.chars().any(|c| c.is_uppercase())
        && stripped_message.chars().all(|c| !c.is_lowercase());
I'm also very new to Rust, so honestly, I don't know left from right and top from bottom yet :D
Jacob Flores
@flores-jacob
Feb 06 2018 15:49
@sbditto85 I tried using string.chars().all(char::is_uppercase) again, looks like it works. Previously, I may have been using string.chars().all(char::is_uppercase()) with the parentheses, that's why it won't compile.
Casey Allred
@sbditto85
Feb 06 2018 16:01
ahh that makes sense
Jacob Flores
@flores-jacob
Feb 06 2018 16:03
I also had to write extra code since the string "WATCH OUT!" won't return True
println!("is upper => {}", "WATCH OUT!".chars().all(char::is_uppercase)); // prints is upper => false
Daniel Bischof
@dbischof90
Feb 06 2018 16:24
Good evening, fellas
Bradley Weston
@bweston92
Feb 06 2018 16:26
Morning
Dylan DPC
@Dylan-DPC
Feb 06 2018 17:47
Morning/Evening
Hans W. Uhlig
@huhlig
Feb 06 2018 19:42
interesting. Any reason why There is no usize::from::<f32>()
Zakarum
@omni-viral
Feb 06 2018 19:42
What usize::from(0.5) should return? @huhlig
Hans W. Uhlig
@huhlig
Feb 06 2018 19:43
alright, what is the proper way to go from a float to a usize then?
Zakarum
@omni-viral
Feb 06 2018 19:43
0.5 as usize I guess
Hans W. Uhlig
@huhlig
Feb 06 2018 19:44
not allowed
Zakarum
@omni-viral
Feb 06 2018 19:44
By whom?
Hans W. Uhlig
@huhlig
Feb 06 2018 19:45
error[E0605]: non-primitive cast: `{float}` as `usize` --> src\audio\engine.rs:35:27 | 35 | let buffer_size = (sample_rate * seconds_buffered) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
Zakarum
@omni-viral
Feb 06 2018 19:45
I have this error sometimes. But when I fix all other errors this one vanishes too
Hans W. Uhlig
@huhlig
Feb 06 2018 19:45
that... makes no sense
Zakarum
@omni-viral
Feb 06 2018 19:45
I agree
Andrey Lesnikov
@ozkriff
Feb 06 2018 19:46
Denis Lisov
@tanriol
Feb 06 2018 19:48
@huhlig Are sample_rate and seconds_buffered just constants for now?
Hans W. Uhlig
@huhlig
Feb 06 2018 19:48
for the moment yeah
  let sample_rate = 44_000.0;
  let seconds_buffered = 600.0;
  let buffer_size = (sample_rate * seconds_buffered) as usize;
  let input_buffer = CircularBuffer::new(buffer_size.into());
  let output_buffer = CircularBuffer::new(buffer_size.into());
  let stream = create_stream(&input_buffer, &output_buffer)?;
This message was deleted
Denis Lisov
@tanriol
Feb 06 2018 19:50

Does the error disappear if you change to

let seconds_buffered = 600.0f32;

?

Hans W. Uhlig
@huhlig
Feb 06 2018 19:52
yeah
it appears to be an artifact of a different section for some reason
Denis Lisov
@tanriol
Feb 06 2018 19:55
I've seen this kind of errors too. It seems to appear when the type of an argument is not known from anywhere (f32 vs f64) if any error stops rustc from getting to the final fallback.
Looks like #40985, closed a few weeks ago, so the error messages in nightly should be better.
Daniel Bischof
@dbischof90
Feb 06 2018 19:58
I can imagine that in the hypothetical scenario when you had full memory and you would ask to cast an f32 as a usize on a 64bit system, you would corrupt the memory
Since u64 takes more space than u32 and can't prevent that at compile time
So rustcstays convervative there
Denis Lisov
@tanriol
Feb 06 2018 20:00
@dbischof90 This is not the real reason :-)
Daniel Bischof
@dbischof90
Feb 06 2018 20:00
But honestly, I don't think that's really the case
Yeah, thought so :D
I just tried to cast some usize variable x as f32 and that's completely valid.
Then erm... nevermind. :D
Joonas Koivunen
@koivunej
Feb 06 2018 21:00
is there an easy way to fold an Iterator<Item = V> with a function FnMut(T, V) -> Result<T, E> so that it would stop when the fold function returns Err and otherwise continue until iterator is exhausted, finally resulting in Result<T, E>?
Denis Lisov
@tanriol
Feb 06 2018 21:48
@koivunej You've described try_fold which, unfortunately, is still unstable.
Joonas Koivunen
@koivunej
Feb 06 2018 21:52
@tanriol oh nice, i wasn't aware of that is already started it's journey to std, or even the name of the operation. thanks!