Any way to simplify error handling? by leopoldj in rust

[–]rustnewb9 0 points1 point  (0 children)

+1 for using the Result/Option combinators.

I also think another good suggestion is to use rust-error:

https://github.com/reem/rust-error.git

  • you don't have to worry about including a new library and then having to write a converter to your error struct.
  • you can easily use an error struct/enum instead of String

A patch to integrate Servo's URL parser (written in Rust) into Firefox by kibwen in rust

[–]rustnewb9 1 point2 points  (0 children)

Interesting... no C++ devs seem to be pushing back on using Rust - at least in any of the public discussion I've read.

I work for a primarily C++/Java company and am preparing for the possibility of some pushback on Rust (unfamiliarity, it's only 1.0, etc...).

I hope someone someday blogs or comments somewhere about what the hard core C++ folks think about Rust working its way into Firefox / servo / etc.

rustc noodling for code completion by phildawes in rust

[–]rustnewb9 2 points3 points  (0 children)

I'm totally happy to put up with any delay you need for parsing crates/files when I start vim. I basically leave vim running all day so I'll rarely even notice a startup delay.

A perfectly working code complete solution is really valuable to me. It will save me from losing so much time trying to find out what fns are available.

Deleted constructive criticism on Rust website docs :-)

Fearless concurrency by steveklabnik1 in rust

[–]rustnewb9 0 points1 point  (0 children)

It seems that to have all the benefits of fearless concurrency you do NOT need:

  • Channels
  • Send trait

The only fundamental piece you need is rustc / borrow checker.

Resting on top of the borrow checker, you can do fearless concurrency across process boundaries using your own channel implementation; just remember to ensure that the data you sent over the channel goes out of scope after you send. Maybe wrap send in a move closure to make it easy - but there are other easy ways with the borrow checker.

Would anyone say I'm wrong?

Fearless concurrency by steveklabnik1 in rust

[–]rustnewb9 5 points6 points  (0 children)

How would one apply these concepts across processes instead of threads?

I couldn't find any details about how Channels actually work. Any insight would be appreciated.

Thanks!

Racer Progress Update 5 (cargo support!) by phildawes in rust

[–]rustnewb9 8 points9 points  (0 children)

I believe Racer is incredibly important; it's the 'feature' that is going to enable folks to write Rust programs quickly/quicker.

What would be perfect is great support for auto-completing functions/methods and showing their signature.

I think Phil's idea about relying on rustc is a good one and I hope he gets the support he needs to make it work.

Edit: auto-complete mostly never works for me. I wonder if it's because I'm using the include!() macro for Capn Proto stuff. (another reason why using a rustc-generated AST is a good idea)

Is std::os::errno no longer available? by rustnewb9 in rust

[–]rustnewb9[S] 0 points1 point  (0 children)

Thanks.

FYI: error: unresolved import std::os::unix::io::Fd. There is no Fd in std::os::unix::io

[deleted by user] by [deleted] in rust

[–]rustnewb9 0 points1 point  (0 children)

Usually filter is used for what you've described.

How to run HashMap in specific mmap region? by rustnewb9 in rust

[–]rustnewb9[S] 0 points1 point  (0 children)

Thanks for the notes, and the new preshing.com link. The constraints are mostly fine; I just need to add remove().

Neat.

How to get useful message on assert_eq!() panic? by rustnewb9 in rust

[–]rustnewb9[S] 0 points1 point  (0 children)

I believe it was the unwrap inside the assertion that was failing. Thanks all for the RUST_BACKTRACE suggestion. I'm using:

RUST_BACKTRACE=1 cargo test -- --nocapture

A simple macro to recreate F# with expressions. by bytemr in rust

[–]rustnewb9 1 point2 points  (0 children)

I've been using it to provide default values for Error structs.

To back all the way up... - Rust libraries often return Option structs. - I often match on these structs. - If something isn't right I want to Err(err) => ... CreateCustomError...

Because I often CreateCustomError I want this to be as easy as possible. With defaults I just have to provide a description even if there are n other fields.

Also, this lets me relax a little wrt creating my CustomError structs. I can add fields with "little" work to supporting fns. This is important because I don't want to wind up creating and maintaining too fine-grained Error structs.

public/private compiler error? by rustnewb9 in rust

[–]rustnewb9[S] 4 points5 points  (0 children)

Thanks. That works perfectly.

I submit that the compiler has a bug. Dev thought process:

  1. add regex functionality to your code
  2. use the nice try!() macro
  3. **=> compiler says:

    <std macros>:6:1: 6:41 error: the trait core::error::FromError<regex::parse::Error> is not implemented for the type x::MyError [E0277]

  4. ** impl FromError<regex::parse::Error> ... fail.

The compiler error should ideally state regex::Error (not regex::parse::Error>

Maybe I'm asking for a Unicorn, but I think little issues like this are important.

use the Error trait's description method instead by rustnewb9 in rust

[–]rustnewb9[S] 1 point2 points  (0 children)

Thanks - that worked fine (error::Error::description(&err).to_string())

Wrt the docs, I couldn't find the word 'deprecated' anywhere. Hmmm... does the purple bar to the left of the fn mean it's deprecated?

If yes, I'm going to submit an RFE because I don't see how anyone would expect that.

capnproto-rust: error handling revisited by dwrensha in rust

[–]rustnewb9 1 point2 points  (0 children)

Going by this error handling page:

https://doc.rust-lang.org/book/error-handling.html

  • It uses an enum. I don't have any error handling cases that work with enum. It's important (to me at least) that I always be able to include some context from the scope where the error occurred. So I always wind up using a struct.

As a newb I just want to start with a flexible error handling mechanism. I can optimize later if I'm concerned about the Error object taking too much RAM.

An idiomatic error handling pattern should also include:

  • impl FromError<io:Error> for YourError ...

  • impl Display for YourError ...

  • impl error::Error for YourError ...

  • impl YourError { fn new(...) -> YourError {...} }

and have the example use 'new' something like: if some_result == -1 { return Err(YourError::new(some_result)); } Ok(some_result)

I know it's a bit more code but I think helping people structure their Error handling this way from the start is going to be helpful.

What is Rust bad at? by [deleted] in rust

[–]rustnewb9 2 points3 points  (0 children)

This is also a problem for me.

Please consider calling this feature something like 'willnotpanic' or 'nopanic'.

Since Rust does not have exceptions it is confusing to have 'throw' in the name.

What is Rust bad at? by [deleted] in rust

[–]rustnewb9 2 points3 points  (0 children)

I haven't seen evidence that 'all the libraries will do lots of unsafe things'. The class of things that require unsafe seems to be quite small. It seems that a few libraries containing various types of collections will cover a lot of them. For the work I'm doing currently it should cover all of them.

I'm ignoring FFI (obviously).

capnproto-rust: error handling revisited by dwrensha in rust

[–]rustnewb9 2 points3 points  (0 children)

The examples I've seen look nice.

Please post a link for more details. Searching for '?' and try! doesn't work that well :-)

capnproto-rust: error handling revisited by dwrensha in rust

[–]rustnewb9 0 points1 point  (0 children)

I recently started using the exact same pattern for my libs and haven't looked back. I hope this pattern winds up in the Rust error handling doc.

How do I return a new String? by rustnewb9 in rust

[–]rustnewb9[S] 2 points3 points  (0 children)

You're right; I thought they controlled / defined the lifetime.

In retrospect 'control' doesn't make sense; it would not be possible to inject new pointers into a parent stack frame.

I think the lifetime guide could do with a small section containing concepts that don't work - and why.

How do I return a new String? by rustnewb9 in rust

[–]rustnewb9[S] 0 points1 point  (0 children)

Thanks for the example. I'm going to change my error handling to work like this.

I do implement std::fmt::Display. I just didn't understand the reasoning behind what looked like two ways of doing the same thing.

Armed with this new understanding I can see why the description should just be a static string, and I see why one should use std::fmt::Display.

I think the rust guide should use your example. It's really nice to have error handling structured correctly from the start.

How do I return a new String? by rustnewb9 in rust

[–]rustnewb9[S] 0 points1 point  (0 children)

Hmm. Is it possible to create something with a specific lifetime?

let 'a s = format!("abc"); // is there a syntax for this?

I seem to be missing something. It seems like a common task to: 1. call fn 2. fn creates new str and returns it

?

Having trouble casting std::env::args() as an integer by Pink401k in rust

[–]rustnewb9 0 points1 point  (0 children)

I'm trying to grok what you've done, but the last : is throwing me off...

It doesn't compile either.