stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

Any chance of webcore::ConversionError being publicly exported?

Open daboross opened this issue 6 years ago • 3 comments

I'm writing a library which uses stdweb for a fairly niche use case and one of the pain points is using generics with TryFrom and stdweb's definitions.

Right now there are a number of places in my codebase that look like this because I can't explicitly name ConversionError:

pub unsafe trait LookConstant {
    type Item: TryFrom<Value, Error = <Reference as TryFrom<Value>>::Error>;

    fn look_code(&self) -> Look;
}

This works, but it's super ugly to have <Xxx as TryFrom<Value>>::Error everywhere rather than being able to explicitly name the type.

Is there any chance that ConversionError is allowed to be publicly referenced? I have no need to construct it, or even access any of it's methods- just having a public type that could be used in type signatures would be a great help.

daboross avatar Sep 14 '18 05:09 daboross

Actually, being able to construct it would be tremendously useful to implement TryFrom<Value> for other objects through references, without resorting to a full serde serialization/deserialization process.

Now my only way to achieve that is to move the checks logic for try_from into javascript and return something that the current implementation doesn't expect.

ASalvail avatar Sep 14 '18 13:09 ASalvail

Hmm.. possibly! I could probably export it as a purely opaque type for now.

Ideally I'd like to figure out a good way to extend it (along with the whole conversion machinery) to include more information so that it could tell you not only what was the expected type, but also what it actually received.

koute avatar Sep 15 '18 23:09 koute

I'll be curious to see what is your solution. AFAIK, the biggest problem is that try_from consumes its input, which wouldn't leave you with much to report on what happened.

ASalvail avatar Sep 16 '18 17:09 ASalvail