These are chat archives for rust-lang/rust

20th
Sep 2017
Moggers
@Moggers
Sep 20 2017 03:08
Can someone gimme some hand with designing polymorphism?
particularly trait objects
coz I shot myself in the foot and I can't figure out how to tie a tourniquet
Cory Duplantis
@ctfhacker
Sep 20 2017 03:10
I'm working on creating FFI bindings for another product. Each of the API endpoints that I can call can effectively return NULL. I have been wrapping all calls in effectively:
let res = API_CALL;
if res.is_null() { None} 
else { Some(NewObject::new(res) }
Should this actually be a Result rather than an Option?
Moggers
@Moggers
Sep 20 2017 03:11
Im not very good at programming in general; but do all the API calls returning NULL indicate the same thing?
ie do they all indicate failure, success (but with no result)?
Cory Duplantis
@ctfhacker
Sep 20 2017 03:12
NULLs just mean that the core functionality can't or didn't return a valid object
Moggers
@Moggers
Sep 20 2017 03:12
I would say at a glance, make them return results if it means something requested could not be completed
while things which are considered completed, but without creating some kind of result, should be an option
Cory Duplantis
@ctfhacker
Sep 20 2017 03:13
Makes sense.. still trying to get a grasp of the rustic intuition between Option and Result
Moggers
@Moggers
Sep 20 2017 03:13
oh
Result is used to describe success status
vs failure status
so Ok, Err
while Some,None of option are both legal/good paths
but that the good path CAN be that theres nothing there (maybe yet)
(I think thats the philosophy behind it)
is that what you mean by rustic intuition?
well; in your example, if the API was a HTTP API, I'd return a Result with Ok for 2xx, Errs for 4xx and 5xx, then for paths which may or may not return a body on success, those would probably be stored in an option
Idk if its an antipattern to use Result<Option<T>,E>
Cory Duplantis
@ctfhacker
Sep 20 2017 03:17
cool cool, thanks!
TatriX
@TatriX
Sep 20 2017 06:27
Hi. What is the best tool currently racer or rls?
Andrey Lesnikov
@ozkriff
Sep 20 2017 06:29
RLS relies on racer right now
TatriX
@TatriX
Sep 20 2017 06:31

Warning: rls is currently very unstable, which can make Emacs hang indefinitely. Using this in production isn't recommended.

So currently I should stick with racer I guess.

Andrey Lesnikov
@ozkriff
Sep 20 2017 06:32
RLS works mostly fine for me with rls-vscode
TatriX
@TatriX
Sep 20 2017 06:33
What it can offer which racer can't?
Andrey Lesnikov
@ozkriff
Sep 20 2017 07:12
Not that much right now (as far as i know): symbol search, code formatting, refactoring (rename, deglob), error squiggles and apply suggestions from errors, build tasks - though most of this features can be implemented by editor/ide itself.
TatriX
@TatriX
Sep 20 2017 07:17
Can it automatically add imports?
Andrey Lesnikov
@ozkriff
Sep 20 2017 07:20
Nope
It's just that racer seems to be a doomed temporary tool - it's useful only until compiler is ready to really support RLS
TatriX
@TatriX
Sep 20 2017 07:27
Any eta on this?
Andrey Lesnikov
@ozkriff
Sep 20 2017 08:02
I'm not sure but I hope somewhere before the end of the year - see https://blog.rust-lang.org/2017/09/18/impl-future-for-rust.html
Steve Klabnik
@steveklabnik
Sep 20 2017 14:24
rls will eventually automatically add imports
Cory Duplantis
@ctfhacker
Sep 20 2017 15:15
I currently have a dependent crate that is purely running bindgen to create bindings.. I am wanting to enable clippy in my vim, but each save will rebuild this entire crate, drastically slowing down productivity.. Can I opt-out of compiling a dependent crate for the time being? The bindings aren't changing every minute ;-)
Robyn Speer
@rspeer
Sep 20 2017 18:24
silly syntax question. Why can't it find type W when I'm trying to use W as a parameter:
pub fn write_npz_stream(writer: &mut W, contents: &Vec<NamedArray>) -> zip::result::ZipResult<()>
where
    W: Write,
{
    ...
}
Steve Klabnik
@steveklabnik
Sep 20 2017 18:24
pub fn write_npz_stream<W>(
^ do that
Robyn Speer
@rspeer
Sep 20 2017 18:24
Oh thanks
Steve Klabnik
@steveklabnik
Sep 20 2017 18:24
with only one bound, i'd drop the where
and write
pub fn write_npz_stream<W: Write>(
personally. up to you :)
Robyn Speer
@rspeer
Sep 20 2017 18:25
Ah, I do like that syntax better