These are chat archives for rust-lang/rust

20th
Oct 2017
Sherzod Mutalov
@shmutalov
Oct 20 2017 10:15
Hello! Sorry for offtopic? Anybody familar with ffmpeg?
Ganesh Prasad Kumble
@0zAND1z
Oct 20 2017 10:47
@shmutalov Sure, What do you want to convert?
Sherzod Mutalov
@shmutalov
Oct 20 2017 10:48
@kggp1995 i think I found what I want :) thanx
Ganesh Prasad Kumble
@0zAND1z
Oct 20 2017 10:49
@shmutalov Cool, are you using any crate? Platform share your success with us
Sherzod Mutalov
@shmutalov
Oct 20 2017 10:50

@kggp1995

I have 39 second audio and 14 minutes video. I would like to "stretch" video duration to audio length (by speeding up the video), without trimming the video

I thinking to use rust-ffmpeg

TatriX
@TatriX
Oct 20 2017 13:24

I'm trying to work with rust on adroid, so I need a way to capture the panic. I'm using:

let result = panic::catch_unwind(|| ggez_test::run());
if let Err(e) = result {
        let ref msg = if let Some(e) = e.downcast_ref::<&'static str>() {
            format!("Got an error: {}", e)
        } else {
            format!("Got an unknown error: {:?}", e)
        };
        log(msg);
    }

If I emit simple panic!("msg") I can read in in the logs, but if it's thrown by the lib then it's Got an unknown error: Any
How can I fix that?

Zakarum
@omni-viral
Oct 20 2017 14:19
I guess lib panics with something that is not &'static str
TatriX
@TatriX
Oct 20 2017 14:20
Yes, but how can I get a string representation for any error?
Zakarum
@omni-viral
Oct 20 2017 14:22
You can't. You get Box<Any + Send + 'static>. Error may not implement Debug or Display
Sergey Noskov
@Albibek
Oct 20 2017 14:23
Error should have .description() afaik
Zakarum
@omni-viral
Oct 20 2017 14:23
@Albibek I wasn't talking about Error trait
Sergey Noskov
@Albibek
Oct 20 2017 14:24
oh, Any, I get it, sorry
Zakarum
@omni-viral
Oct 20 2017 14:24
And Error requires Display btw
TatriX
@TatriX
Oct 20 2017 14:24
Can I somehow try to cast it to something displayable?
Zakarum
@omni-viral
Oct 20 2017 14:25
To cast an Any to something you have to know what it is
TatriX
@TatriX
Oct 20 2017 14:25
So basically I have no sane way to debug that.
Aleksey Kladov
@matklad
Oct 20 2017 14:26

I think yes :(

Here's a thread about this problem from some time ago: https://internals.rust-lang.org/t/specialization-for-better-debug-for-any/4029

Hm, I think you can override the fucntion whicch is called to print the panic message
Zakarum
@omni-viral
Oct 20 2017 14:32
@TatriX The best you can do is try to cast Any in some types and inform the user. If all attempts are failed you just say that you got "Unknown error"
TatriX
@TatriX
Oct 20 2017 14:33
Well, with hook it's now { file: "/checkout/src/libcore/result.rs", line: 906, col: 4 }
Which isn't very usefull too.
Maybe I can get a backtrace somehow?
The panic goes from the library so I have no idea what error it can be
Zakarum
@omni-viral
Oct 20 2017 14:34
You can just go and look
You have the path now :smile:
TatriX
@TatriX
Oct 20 2017 14:35
Obviously it's somethink like unwrap
of the result
So it's useless without backtrace or message or something
Zakarum
@omni-viral
Oct 20 2017 14:36
I guess it panics with String
TatriX
@TatriX
Oct 20 2017 14:36
The only working way to debug now is inserting panic!("x") in the code to detect if the app panic before or after this line
Zakarum
@omni-viral
Oct 20 2017 14:37
I believe 99% of code panics with either str or String
Steve Klabnik
@steveklabnik
Oct 20 2017 14:37
yeah, given that panics aren't really an error-handling mechanism, using other things rarely makes sense
i doubt many rust programmers even realize that you can panic with things that aren't str/String
Zakarum
@omni-viral
Oct 20 2017 14:38
@steveklabnik Yeah. panic! is the machanism to tell the user about error. Not to handle it in the program
TatriX
@TatriX
Oct 20 2017 14:38
Well unwrap() do a panic for a programer
Steve Klabnik
@steveklabnik
Oct 20 2017 14:38
well, i'd say "for a bug"
TatriX
@TatriX
Oct 20 2017 14:38
With a usefull nothingness inside
Steve Klabnik
@steveklabnik
Oct 20 2017 14:38
it's not how your supposed to tell users about errors you know about, it's for errors you don't
but anyway, that doesn't help @TatriX
Zakarum
@omni-viral
Oct 20 2017 14:39
unwrap() panics with a message and whatever <E as Debug>::fmt puts in `Formatter
Putting it all in Stirng
You can just print it yourself
On android
I can't see the problem actually
TatriX
@TatriX
Oct 20 2017 14:41
I don't understand what do you mean. I'm simply running a sample code, which uses a lot of libraries, from ggez -> gfx_window_sdl -> sdl2
And it crashes
With Any in my hand.
Zakarum
@omni-viral
Oct 20 2017 14:42
let result = panic::catch_unwind(|| ggez_test::run());
if let Err(e) = result {
        let ref msg = if let Some(e) = e.downcast_ref::<&'static str>() {
            format!("Got an error: {}", e)
        } else if let Some(e) = e.downcast_ref::<String>()   {
            format!("Got an error: {}", e)
        } else {
            format!("Got an unknown error: {:?}", e)
        };
        log(msg);
    }
This is what I mean
TatriX
@TatriX
Oct 20 2017 14:43
Oh. That works, finally. Thanks ;)
Got an error: calledResult::unwrap()on anErrvalue: WindowError(WindowBuildError(SdlError("Could not initialize OpenGL / GLES library")))
Steve Klabnik
@steveklabnik
Oct 20 2017 14:43
let ref msg?
ah, i see, since log takes &str
Zakarum
@omni-viral
Oct 20 2017 14:44
@steveklabnik I've copied that part. All questions to @TatriX :smile:
Steve Klabnik
@steveklabnik
Oct 20 2017 14:44
i'd write let msg and log(&msg) personally
Zakarum
@omni-viral
Oct 20 2017 14:44
So do I
It less symbols this way
Steve Klabnik
@steveklabnik
Oct 20 2017 14:45
yeah it's all good. i mean, it works
it's slightly surprising
Zakarum
@omni-viral
Oct 20 2017 14:45
I use ref only inside patterns
TatriX
@TatriX
Oct 20 2017 14:45
My cursor was near the let, so it was easier to type ref, hehe
Alyani
@notsonotso
Oct 20 2017 16:13
CTO just decided to scrap Rust :angry:
Steve Klabnik
@steveklabnik
Oct 20 2017 16:13
for what reason?
Alyani
@notsonotso
Oct 20 2017 16:15
cited reasons are 1. build times hampers productivity, 2. almost nobody available for hire
everyone here agrees with 1, while 2 is "meh, they can learn it"
anyway, i still wanna work on Rust to keep myself up to date. Thinking about getting into the compiler code base... any low hanging fruit?
to get started
Steve Klabnik
@steveklabnik
Oct 20 2017 16:17
Alyani
@notsonotso
Oct 20 2017 16:17
definitely rust-lang/rust-roadmap#1
Rui Azevedo
@neu-rah
Oct 20 2017 16:57
:+1:
Judson Lester
@nyarly
Oct 20 2017 18:18
Did I just dream fn X(...) impl Trait ? Forever ago, I thought it was experimental?
Can't find it at all now.
Steve Klabnik
@steveklabnik
Oct 20 2017 18:19
it's fn X(...)-> impl Trait
it's currently under the conservative_impl_trait feature gate
work is underway to stabilize it
Judson Lester
@nyarly
Oct 20 2017 18:21
I keep trying to find it, but the impl Struct syntax and the "impl Future" initiative keeps shadowing it in Google searches.
Judson Lester
@nyarly
Oct 20 2017 18:23
Thanks