These are chat archives for rust-lang/rust

27th
Jan 2018
Kelly Thomas Kline
@kellytk
Jan 27 2018 02:54
Where in the documentation can I look to find guidance on how to use several different error types for a FromStr implementation? I can return different error type instances via Err() as appropriate, but what I'm confused by is what should happen to the single type Err = InputParseError; line?
Kelly Thomas Kline
@kellytk
Jan 27 2018 04:56
Is the correct style to retain the type Err = InputParseError; line, derive additional error types from InputParseError and return those from from_str?
Brian Merchant
@bzm3r
Jan 27 2018 05:15
hi all, when i run rustfmt on a file (rustfmt <somefile>.rs), i get the following message:
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', C:\Users\Brian Merchant\.cargo\registry\src\github.com-1ecc6299db9ec823\rustc-ap-rustc_errors-12.0.0\emitter.rs:1269:23
note: Run with `RUST_BACKTRACE=1` for a backtrace.
any idea why this is?
Peter Atashian
@retep998
Jan 27 2018 08:06
@bzm3r What terminal are you using? Powershell? cmd? Git bash? Something more exotic?
Michal 'vorner' Vaner
@vorner
Jan 27 2018 08:24
Hello. I'd like to make some of my dev-dependencies be pulled in only in nightly. They are nightly only and for benchmarks and I want my tests still work on stable as well. However, cargo tells me dev dependencies can't be optional. Is there a canonical trick how to solve this?
Kelly Thomas Kline
@kellytk
Jan 27 2018 08:54
Can a struct be extended? I would like to create several different-but-related structs which share a struct containing a common set of fields
Michal 'vorner' Vaner
@vorner
Jan 27 2018 08:59
@kellytk You can compose them ‒ have a struct for the common parts and then bunch of other structs each containing the first one.
Michal 'vorner' Vaner
@vorner
Jan 27 2018 09:01
There's no special syntax for it.
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:01
Would the shared struct be a field of the other structs?
Michal 'vorner' Vaner
@vorner
Jan 27 2018 09:02
struct Common {
  a: u64,
}
struct Bigger {
  common: Common,
  // Other stuff
}

impl Bigger {
  fn new() -> Bigger {
    Bigger {
      common: Common {
        a: 42,
      },
    }
  }
}
Yes, just a field.
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:06
Would struct Message { text: String }; struct RichMessage: Message { media: Media} // RichMessage.text inferred be an improvement?
Michal 'vorner' Vaner
@vorner
Jan 27 2018 09:10
Rust doesn't have inheritance on purpose. It introduces bunch of problems.
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:10
I can appreciate that, vis-a-vis shadowing issues in 'flattening' interfaces et al. Thanks
What I'd like to do is extend a basic FromStr implementation on a struct, from using a single custom Error (currently implemented as a struct) type to having several more specific error types that are all derived from the original shared default Error type. Is that regular design?
Roman Proskuryakov
@kpp
Jan 27 2018 09:21
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:26
@kpp That appears to be a solution, thanks I'll try it
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:34
@kpp Do you happen to have an opinion on error-chains as an alternative?
Roman Proskuryakov
@kpp
Jan 27 2018 09:35
I don't know, sorry.
Michal 'vorner' Vaner
@vorner
Jan 27 2018 09:44
Error chain is older and more verbose. But it tries to solve the same problem.
Kelly Thomas Kline
@kellytk
Jan 27 2018 09:47
@vorner Do you have a personal opinion that one is better than the other in some way, and if so would you characterize it?
Michal 'vorner' Vaner
@vorner
Jan 27 2018 09:48
I use failure now, before it was created I used error chain. As I said, there's not that big difference between them if you just want to unify the errors, only that with failure it's much less work
Kelly Thomas Kline
@kellytk
Jan 27 2018 11:16
Thanks
Adel Prokurov
@aprokurov
Jan 27 2018 12:46

Guys, i need help with one error in gtk-rs:

error[E0599]: no function or associated item named `new_from_string` found for type `gtk::Builder` in the current scope
  --> src/main.rs:14:15
   |
14 | let builder = gtk::Builder::new_from_string(glade_src);
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `gtk::Builder`

How i can fix that error?

Denis Lisov
@tanriol
Jan 27 2018 12:49
add_from_string?
Or add feature v3_10, as new_from_string requires it.
Adel Prokurov
@aprokurov
Jan 27 2018 13:04
Still get that error:(
Denis Lisov
@tanriol
Jan 27 2018 13:04
With v3_10?
Adel Prokurov
@aprokurov
Jan 27 2018 13:04
with add_from_string
how to add feature?
Denis Lisov
@tanriol
Jan 27 2018 13:07
Adel Prokurov
@aprokurov
Jan 27 2018 13:08
Thanks, going to try with features 3.10
Brian Merchant
@bzm3r
Jan 27 2018 19:45
@retep998 I am using simple old cmd.exe