pub fn read(name: &str) -> Result<ParamType, Error> {
		// check if it is a fixed or dynamic array.
		match name.chars().last() {
			Some(']') => {
				// take number part
				let num: String = name.chars()
					.rev()
					.skip(1)
					.take_while(|c| *c != '[')
					.collect::<String>()
					.chars()
					.rev()
					.collect();

				let count = name.chars().count();
				if num.is_empty() {
					// we already know it's a dynamic array!
					let subtype = try!(Reader::read(&name[..count - 2]));
					return Ok(ParamType::Array(Box::new(subtype)));
				} else {
					// it's a fixed array.
					let len = try!(usize::from_str_radix(&num, 10));
					let subtype = try!(Reader::read(&name[..count - num.len() - 2]));
					return Ok(ParamType::FixedArray(Box::new(subtype), len));
				}
			}
			Some(')') => {
				if name.chars().next() == Some('(') {
					let mut subtypes = Vec::new();
					let mut nested = 0isize;
					let mut last_item = 1;

					for (pos, c) in name.chars().enumerate() {
						match c {
							'(' => {
								nested += 1;
							}
							')' => {
								nested -= 1;
								if nested < 0 {
									return Err(ErrorKind::InvalidName(name.to_owned()).into());
								} else if nested == 0 {
									let sub = &name[last_item..pos];
									let subtype = Reader::read(sub)?;
									subtypes.push(subtype);
									last_item = pos + 1;
								}
							}
							',' if nested == 1 => {
								let sub = &name[last_item..pos];
								let subtype = Reader::read(sub)?;
								subtypes.push(subtype);
								last_item = pos + 1;
							}
							_ => ()
						}
					}
					return Ok(ParamType::Tuple(subtypes));
				}

			}
			_ => ()
		}

		let result = match name {
			"address" => ParamType::Address,
			"bytes" => ParamType::Bytes,
			"bool" => ParamType::Bool,
			"string" => ParamType::String,
			"int" => ParamType::Int(256),
			"uint" => ParamType::Uint(256),
			"tuple"=> ParamType::Tuple(vec![]),
			s if s.starts_with("int") => {
				let len = try!(usize::from_str_radix(&s[3..], 10));
				ParamType::Int(len)
			},
			s if s.starts_with("uint") => {
				let len = try!(usize::from_str_radix(&s[4..], 10));
				ParamType::Uint(len)
			},
			s if s.starts_with("bytes") => {
				let len = try!(usize::from_str_radix(&s[5..], 10));
				ParamType::FixedBytes(len)
			},
			_ => {
				return Err(ErrorKind::InvalidName(name.to_owned()).into());
			}
		};

		Ok(result)
	}
/// Converts string to param type.
Converts string to param type.
Converts string to param type .
pub fn read(name: &str) -> Result<ParamType, Error> {
		// check if it is a fixed or dynamic array.
		match name.chars().last() {
			Some(']') => {
				// take number part
				let num: String = name.chars()
					.rev()
					.skip(1)
					.take_while(|c| *c != '[')
					.collect::<String>()
					.chars()
					.rev()
					.collect();
				let count = name.chars().count();
				if num.is_empty() {
					// we already know it's a dynamic array!
					let subtype = try!(Reader::read(&name[..count - 2]));
					return Ok(ParamType::Array(Box::new(subtype)));
				} else {
					// it's a fixed array.
					let len = try!(usize::from_str_radix(&num, 10));
					let subtype = try!(Reader::read(&name[..count - num.len() - 2]));
					return Ok(ParamType::FixedArray(Box::new(subtype), len));
				}
			}
			Some(')') => {
				if name.chars().next() == Some('(') {
					let mut subtypes = Vec::new();
					let mut nested = 0isize;
					let mut last_item = 1;
					for (pos, c) in name.chars().enumerate() {
						match c {
							'(' => {
								nested += 1;
							}
							')' => {
								nested -= 1;
								if nested < 0 {
									return Err(ErrorKind::InvalidName(name.to_owned()).into());
								} else if nested == 0 {
									let sub = &name[last_item..pos];
									let subtype = Reader::read(sub)?;
									subtypes.push(subtype);
									last_item = pos + 1;
								}
							}
							',' if nested == 1 => {
								let sub = &name[last_item..pos];
								let subtype = Reader::read(sub)?;
								subtypes.push(subtype);
								last_item = pos + 1;
							}
							_ => ()
						}
					}
					return Ok(ParamType::Tuple(subtypes));
				}
			}
			_ => ()
		}
		let result = match name {
			"address" => ParamType::Address,
			"bytes" => ParamType::Bytes,
			"bool" => ParamType::Bool,
			"string" => ParamType::String,
			"int" => ParamType::Int(256),
			"uint" => ParamType::Uint(256),
			"tuple"=> ParamType::Tuple(vec![]),
			s if s.starts_with("int") => {
				let len = try!(usize::from_str_radix(&s[3..], 10));
				ParamType::Int(len)
			},
			s if s.starts_with("uint") => {
				let len = try!(usize::from_str_radix(&s[4..], 10));
				ParamType::Uint(len)
			},
			s if s.starts_with("bytes") => {
				let len = try!(usize::from_str_radix(&s[5..], 10));
				ParamType::FixedBytes(len)
			},
			_ => {
				return Err(ErrorKind::InvalidName(name.to_owned()).into());
			}
		};
		Ok(result)
	}
pub fn read ( name : & str ) -> Result < ParamType , Error > { // check if it is a fixed or dynamic array. match name . chars ( ) . last ( ) { Some ( ']' ) => { // take number part let num : String = name . chars ( ) . rev ( ) . skip ( 1 ) . take_while ( | c | * c != '[' ) . collect :: < String > ( ) . chars ( ) . rev ( ) . collect ( ) ; let count = name . chars ( ) . count ( ) ; if num . is_empty ( ) { // we already know it's a dynamic array! let subtype = try ! ( Reader read ( name [ count 2 ] ) ) ; return Ok ( ParamType :: Array ( Box :: new ( subtype ) ) ) ; } else { // it's a fixed array. let len = try ! ( usize from_str_radix ( num 10 ) ) ; let subtype = try ! ( Reader read ( name [ count num len ( ) 2 ] ) ) ; return Ok ( ParamType :: FixedArray ( Box :: new ( subtype ) , len ) ) ; } } Some ( ')' ) => { if name . chars ( ) . next ( ) == Some ( '(' ) { let mut subtypes = Vec :: new ( ) ; let mut nested = 0isize ; let mut last_item = 1 ; for ( pos , c ) in name . chars ( ) . enumerate ( ) { match c { '(' => { nested += 1 ; } ')' => { nested -= 1 ; if nested < 0 { return Err ( ErrorKind :: InvalidName ( name . to_owned ( ) ) . into ( ) ) ; } else if nested == 0 { let sub = & name [ last_item .. pos ] ; let subtype = Reader :: read ( sub ) ? ; subtypes . push ( subtype ) ; last_item = pos + 1 ; } } ',' if nested == 1 => { let sub = & name [ last_item .. pos ] ; let subtype = Reader :: read ( sub ) ? ; subtypes . push ( subtype ) ; last_item = pos + 1 ; } _ => ( ) } } return Ok ( ParamType :: Tuple ( subtypes ) ) ; } } _ => ( ) } let result = match name { " " => ParamType :: Address , " " => ParamType :: Bytes , " " => ParamType :: Bool , " " => ParamType :: String , " " => ParamType :: Int ( 256 ) , " " => ParamType :: Uint ( 256 ) , " " => ParamType :: Tuple ( vec ! [ ] ) , s if s . starts_with ( " " ) => { let len = try ! ( usize from_str_radix ( s [ 3 ] 10 ) ) ; ParamType :: Int ( len ) } , s if s . starts_with ( " " ) => { let len = try ! ( usize from_str_radix ( s [ 4 ] 10 ) ) ; ParamType :: Uint ( len ) } , s if s . starts_with ( " " ) => { let len = try ! ( usize from_str_radix ( s [ 5 ] 10 ) ) ; ParamType :: FixedBytes ( len ) } , _ => { return Err ( ErrorKind :: InvalidName ( name . to_owned ( ) ) . into ( ) ) ; } } ; Ok ( result ) }
Converts string to param type.
Converts string to param type .
name
&str
name
&str