These are chat archives for rust-lang/rust

10th
Jul 2018
Sylwester Rąpała
@xoac
Jul 10 2018 11:23
Is there a common way to implement From<int> for MyType ?
I mean that in once I can get all i8 - i64
and &i8 - to &i64
Zakarum
@omni-viral
Jul 10 2018 11:24
You can't convert &i8 to &i64
Sylwester Rąpała
@xoac
Jul 10 2018 11:24
ok But I just need a copy of value
Zakarum
@omni-viral
Jul 10 2018 11:25
The common way to implement From<Type> for MyType is

impl From<Type> for MyType {
  fn from(value: Type) -> MyType {
    ...
  }
}
There are no "common" shortcuts
Sylwester Rąpała
@xoac
Jul 10 2018 11:26
Just asking about not to reapet myself so many times
Zakarum
@omni-viral
Jul 10 2018 11:26
Do you need to implement it for many MyTypes?
Or from many int types?
Sylwester Rąpała
@xoac
Jul 10 2018 11:27
Zakarum
@omni-viral
Jul 10 2018 11:27
In either of those cases - macro_rules! is you friend
Sylwester Rąpała
@xoac
Jul 10 2018 11:28
I don't know how to use macro_rules! yet. So for now I will do it manually :)
Do Duy
@juchiast
Jul 10 2018 12:49

Hello, I'm unable to use nom::digit to parse number. Here is the code:

println!("{:?}", nom::digit("123"));

It prints out Err(Incomplete(Size(1))).

It appears that the input has to end in a non-digit character.

How can I fix this, without having to manually rewrite a digit parser?
And without mutating the input, too.
Denis Lisov
@tanriol
Jul 10 2018 12:55
How about nom::digit(CompleteStr(input))?
Do Duy
@juchiast
Jul 10 2018 13:20
Thanks, that works.
Do Duy
@juchiast
Jul 10 2018 13:52
I downgraded to nom 3, it's much nicer without the CompleteStr thing.
Denis Lisov
@tanriol
Jul 10 2018 13:53
I'd really doubt the idea of starting a project with an already outdated library version...
Zakarum
@omni-viral
Jul 10 2018 20:02
If I have owned T and there is a function fn foo<'a>(&'a mut T) -> &'a mut Y is it valid to assume after calling foo that returned Y won't be dropped until T touched again?