pub struct BinaryHash { /* private fields */ }
Expand description
Binary hash code for a given GeoLocation
with specific precision
Implementations§
Source§impl BinaryHash
impl BinaryHash
Sourcepub fn new() -> BinaryHash
pub fn new() -> BinaryHash
Create an empty BinaryHash
Sourcepub fn from_string(s: &str) -> BinaryHash
pub fn from_string(s: &str) -> BinaryHash
Create a BinaryHash
from a String
§Example
let bh=geohashrust::BinaryHash::from_string("11100110");
assert_eq!(bh.to_string(), "11100110");
Sourcepub fn encode(l: &GeoLocation, precision: u8) -> BinaryHash
pub fn encode(l: &GeoLocation, precision: u8) -> BinaryHash
Encode a GeoLocation
into binary hash
§Example
let l=geohashrust::GeoLocation{
latitude:31.23,
longitude:121.473,
};
let bh=geohashrust::BinaryHash::encode(&l, 8);
assert_eq!(bh.to_string(), "11100110");
Sourcepub fn decode(&self) -> BoundingBox
pub fn decode(&self) -> BoundingBox
Decode binary hash into a BoundingBox
§Example
let bh=geohashrust::BinaryHash::from_string("11100");
let bbox=bh.decode();
assert!(bbox.contains(&geohashrust::GeoLocation::from_coordinates(21.0, 113.0)));
Sourcepub fn decode_string(s: &str) -> BoundingBox
pub fn decode_string(s: &str) -> BoundingBox
Decode binary hash into a BoundingBox
§Example
let bbox=geohashrust::BinaryHash::decode_string("11100");
assert!(bbox.contains(&geohashrust::GeoLocation::from_coordinates(21.0, 113.0)));
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Convert BinaryHash
to a String
§Example
let bh=geohashrust::BinaryHash::from_string("11100110");
assert_eq!(bh.to_string(), "11100110");
Sourcepub fn len(&self) -> u8
pub fn len(&self) -> u8
Return the count of effective bits in the binary hash
§Example
let mut bh=geohashrust::BinaryHash::new();
assert_eq!(bh.len(), 0);
bh.push(true);
bh.push(true);
assert_eq!(bh.len(), 2);
bh.push(false);
bh.push(true);
assert_eq!(bh.len(), 4);
Sourcepub fn empty(&self) -> bool
pub fn empty(&self) -> bool
Test if the binary hash is empty
§Example
let mut bh=geohashrust::BinaryHash::new();
assert!(bh.empty());
bh.push(true);
bh.push(true);
bh.push(false);
bh.push(true);
assert!(!bh.empty());
Trait Implementations§
Source§impl Clone for BinaryHash
impl Clone for BinaryHash
Source§fn clone(&self) -> BinaryHash
fn clone(&self) -> BinaryHash
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for BinaryHash
impl Default for BinaryHash
Source§fn default() -> BinaryHash
fn default() -> BinaryHash
Returns the “default value” for a type. Read more
Source§impl PartialEq for BinaryHash
impl PartialEq for BinaryHash
impl Copy for BinaryHash
impl StructuralPartialEq for BinaryHash
Auto Trait Implementations§
impl Freeze for BinaryHash
impl RefUnwindSafe for BinaryHash
impl Send for BinaryHash
impl Sync for BinaryHash
impl Unpin for BinaryHash
impl UnwindSafe for BinaryHash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more