These are chat archives for rust-lang/rust

1st
Apr 2019
Brian Knapp
@knappador
Apr 01 00:31
Linking error. xxx is undefined
kylegoetz
@kylegoetz
Apr 01 01:58

I'm seeing some Rust functions with header pub fn foo(myParams) -> Result<Type> rather than Result<Type, SomeError>. When I try this in my code, I get an error that Result needs two params and I've only supplied one. Here is an example of a Rust lib that does this: https://docs.rs/dotenv/0.10.1/src/dotenv/lib.rs.html#45-48

How? I'm having difficulty defining my own function that returns Result because I don't know what to put for the second param in Result<V, E> (Error is not in scope, VarError is not, etc.). Haven't figured out where these come from and was trying to copy other source code.

matrixbot
@matrixbot
Apr 01 03:16

Zanny > <@gitter_kylegoetz:matrix.org> I'm seeing some Rust functions with header pub fn foo(myParams) -> Result<Type> rather than Result<Type, SomeError>. When I try this in my code, I get an error that Result needs two params and I've only supplied one. Here is an example of a Rust lib that does this: https://docs.rs/dotenv/0.10.1/src/dotenv/lib.rs.html#45-48

How? I'm having difficulty defining my own function that returns Result because I don't know what to put for the second param in Result<V, E> (Error is not in scope, VarError is not, etc.). Haven't figured out where these come from and was trying to copy other source code.

The definition of the Result you linked is here: https://docs.rs/dotenv/0.10.1/dotenv/type.Result.html a lot of libraries will typedef Result<T, CRATE_ERR> to Result<T>

Kelly Thomas Kline
@kellytk
Apr 01 05:39
How can I import the types JsonServerError and ServerError referred to by http_failure at https://docs.rs/google-youtube3/1.0.8+20180511/google_youtube3/trait.Delegate.html so that copying the signature in an implementation of the trait doesn't generate an error?
thojest
@thojest
Apr 01 10:30
does anybody know an elegant way for error handling concerning logging and conversion
i basically want to use the ? operator, but I want to log the error and then convert it into another error
probably using map_err together with ? operator
Ichoran
@Ichoran
Apr 01 14:14

@sam0x17 - Why count? Let the compiler count for you. Just type in any old number for the array length and wait for it to complain:

  = note: expected type `[u64; 10]`
             found type `[u64; 5]`

Then you know how to fix it. (It's a shame it won't infer it, but at least it will tell you what it should have inferred.)

Kelly Thomas Kline
@kellytk
Apr 01 20:03
Any users of the google-apis-rs crate here? I'm confused about how it's designed to work and I'd appreciate it if I could ask you a few conceptual questions
Austin Baugh
@austinsheep
Apr 01 22:46
Hi, I'm new to Rust and was wondering if an env::Arg could be accessed by the callback function passed to libc::atexit()
Brian Knapp
@knappador
Apr 01 22:51
@austinsheep as long as the function requires no arguments, you will find that you can call it from any scope
Austin Baugh
@austinsheep
Apr 01 23:02
I must be doing something wrong, shouldn't this print the command line arguments?
extern fn cb() {
    dbg!(::std::env::args());
}

fn main() {
    unsafe { libc::atexit(cb); }
}
matrixbot
@matrixbot
Apr 01 23:19
moltonel Maybe it's racy ? I know it would be in C; not sure about rust. Try flushing stdout in cb().
matrixbot
@matrixbot
Apr 01 23:25
moltonel Also: using atexit like that doesn't feel very rust. What about for example putting your dbg!(::std::env::args()) in a struct's Drop impl ? Or just at the end of main, it's trustworthyer than a C main.
Sam Johnson
@sam0x17
Apr 01 23:45
haha nice trick @Ichoran