33 Geohash Neighbor
Objective
Create an R function that finds a directional neighbor for a geohash.
We now know how to take a string in R and convert it into an enum
and what a &str
is.
We’re going to begin building up a gh_neighbor()
function which takes two arguments:
pub fn neighbor(
: &str,
hash_str: Direction,
direction-> Result<String, GeohashError> )
and returns a geohash as a string. We’re going to create an R wrapper to this function.
Exercise
- Create a new function
gh_encode()
which has two arguments:geohash: String
, anddirection: String
and returns aString
- Import
neighbor()
fromgeohash
- Use
as_direction()
to process thedirection
arguments - Use
neighbor()
to return the resultant geohash (you can unwrap for now)- Note: borrow
geohash
asneighbor()
expects a&str
—i.e.neighbor(&geohash, ...)
- Note: borrow
View solution
#[extendr]
fn gh_neighbor(geohash: String, direction: String) -> String {
let dir = as_direction(direction);
&geohash, dir).unwrap()
neighbor(}