rust - Implementing the From trait for a ParseIntError -


when using try! macro, uses trait transform error desired error.

i transform errors own type. goes great e.g. io::error, can't work error type core.

use std::io;  pub struct parsererror {     pub message: string, }  impl from<io::error> parsererror {     fn from(e: io::error) -> parsererror {         parsererror{message: format!("generic io error: {}", e.description())}     } } 

this works doing try! on io. parsing:

fn parse_string(s: &str) -> result<u64, parsererror> {     let = try!(s.parse::<u64>());     return ok(i); } 

my error says:

error: trait core::convert::from<parser::parsererror> not implemented type `core::num::parseinterror

i tried implement from:

impl from<core::num::parseinterror> parsererror {     fn from(_: core::num::parseinterror) -> parsererror {         parsererror{message: "invalid data type".to_string()}     } } 

but can't core imported. how this?

the modules core reexported std. can fix error replacing core std in code:

impl from<std::num::parseinterror> parsererror {     fn from(_: std::num::parseinterror) -> parsererror {         parsererror{message: "invalid data type".to_string()}     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -