pub fn from_words<'a, I, S>(words: I) -> Result<(f64, f64), Error<'a>>
where I: Iterator<Item=&'a S> + ExactSizeIterator,
      S: AsRef<str> + 'a + ?Sized
{
    if words.len() > 5 {
        return Err(Error::TooManyWords(words.len()))
    }

    let (lat, lng) = words.enumerate()
        .map(|(idx, word)| {
            let word_idx_limit = RASTER_SIZE[idx].0 * RASTER_SIZE[idx].1;
            let word_idx = get_word_idx(word.as_ref())?;

            if word_idx >= word_idx_limit {
                return Err(Error::InvalidWord(word.as_ref()));
            }

            let lat_idx = word_idx / RASTER_SIZE[idx].1;
            let long_idx = word_idx % RASTER_SIZE[idx].1;

            Ok((
                (lat_idx as f64) * TILES_SIZES[idx],
                (long_idx as f64) * TILES_SIZES[idx],
            ))
        })
        .try_fold((-90f64, -180f64), |acc, coords| {
            match coords {
                Ok((lat, long)) => Ok((acc.0 + lat, acc.1 + long)),
                Err(e) => Err(e)
            }
        })?;

    Ok((lat, lng))
}
/// Decode words supplied as iterator over string slices.
///
/// # Example:
/// ```
/// use where39::from_words;
///
/// let words = &["slush", "battle", "damage", "dentist"][..];
///
/// let (lat, lng) = from_words(words.iter()).unwrap();
/// assert_eq!(lat, 51.02561728383f64);
/// assert_eq!(lng, 13.72333333297f64);
/// ```
Decode words supplied as iterator over string slices.
Decode words supplied as iterator over string slices .
pub fn from_words<'a, I, S>(words: I) -> Result<(f64, f64), Error<'a>>
where I: Iterator<Item=&'a S> + ExactSizeIterator,
      S: AsRef<str> + 'a + ?Sized
{
    if words.len() > 5 {
        return Err(Error::TooManyWords(words.len()))
    }
    let (lat, lng) = words.enumerate()
        .map(|(idx, word)| {
            let word_idx_limit = RASTER_SIZE[idx].0 * RASTER_SIZE[idx].1;
            let word_idx = get_word_idx(word.as_ref())?;
            if word_idx >= word_idx_limit {
                return Err(Error::InvalidWord(word.as_ref()));
            }
            let lat_idx = word_idx / RASTER_SIZE[idx].1;
            let long_idx = word_idx % RASTER_SIZE[idx].1;
            Ok((
                (lat_idx as f64) * TILES_SIZES[idx],
                (long_idx as f64) * TILES_SIZES[idx],
            ))
        })
        .try_fold((-90f64, -180f64), |acc, coords| {
            match coords {
                Ok((lat, long)) => Ok((acc.0 + lat, acc.1 + long)),
                Err(e) => Err(e)
            }
        })?;
    Ok((lat, lng))
}
pub fn from_words < ' a , I , S > ( words : I ) -> Result < ( f64 , f64 ) , Error < ' a > > where I : Iterator < Item = & ' a S > + ExactSizeIterator , S : AsRef < str > + ' a + ? Sized { if words . len ( ) > 5 { return Err ( Error :: TooManyWords ( words . len ( ) ) ) } let ( lat , lng ) = words . enumerate ( ) . map ( | ( idx , word ) | { let word_idx_limit = RASTER_SIZE [ idx ] . 0 * RASTER_SIZE [ idx ] . 1 ; let word_idx = get_word_idx ( word . as_ref ( ) ) ? ; if word_idx >= word_idx_limit { return Err ( Error :: InvalidWord ( word . as_ref ( ) ) ) ; } let lat_idx = word_idx / RASTER_SIZE [ idx ] . 1 ; let long_idx = word_idx % RASTER_SIZE [ idx ] . 1 ; Ok ( ( ( lat_idx as f64 ) * TILES_SIZES [ idx ] , ( long_idx as f64 ) * TILES_SIZES [ idx ] , ) ) } ) . try_fold ( ( - 90f64 , - 180f64 ) , | acc , coords | { match coords { Ok ( ( lat , long ) ) => Ok ( ( acc . 0 + lat , acc . 1 + long ) ) , Err ( e ) => Err ( e ) } } ) ? ; Ok ( ( lat , lng ) ) }
Decode words supplied as iterator over string slices.
Decode words supplied as iterator over string slices .
words
I
example:
```
use where39::from_words.




` ` ` use where39 :: from_words .