Struct MmdbReader
pub struct MmdbReader { /* private fields */ }net only.Expand description
A zero-copy reader over a MaxMind DB.
The database buffer is shared, so cloning a reader is cheap and a single
database can be queried concurrently from many tasks without locks. The
bytes are either held in memory (Self::from_bytes / Self::open) or,
with the mmap feature, memory-mapped from disk via open_mmap.
Implementations§
§impl MmdbReader
impl MmdbReader
pub fn from_bytes(bytes: impl Into<Bytes>) -> Result<MmdbReader, GeoIpError>
pub fn from_bytes(bytes: impl Into<Bytes>) -> Result<MmdbReader, GeoIpError>
Build a reader from raw database bytes already held in memory.
§Errors
Returns GeoIpError if the bytes are not a valid MaxMind DB or use
an unsupported record size / format version.
pub fn open(path: impl AsRef<Path>) -> Result<MmdbReader, GeoIpError>
pub fn open(path: impl AsRef<Path>) -> Result<MmdbReader, GeoIpError>
Read a MaxMind DB from disk into memory.
The whole file is read into a shared buffer. With the mmap feature,
open_mmap maps the file instead for a smaller resident set on very
large databases.
§Errors
Returns GeoIpError::Io if the file cannot be read, or another
GeoIpError if it is not a valid database.
pub fn open_mmap(path: impl AsRef<Path>) -> Result<MmdbReader, GeoIpError>
Available on crate feature mmap only.
pub fn open_mmap(path: impl AsRef<Path>) -> Result<MmdbReader, GeoIpError>
mmap only.Memory-map a MaxMind DB from disk instead of reading it into memory.
Lookups fault in only the pages they touch, so a large database costs little resident memory. The mapping is held for the reader’s lifetime.
The file must not be modified or truncated while the reader is alive, or lookups may observe garbage (or fault on some platforms).
§Errors
Returns GeoIpError::Io if the file cannot be opened or mapped, or
another GeoIpError if it is not a valid database.
pub fn with_language(self, lang: impl Into<Box<str>>) -> MmdbReader
pub fn with_language(self, lang: impl Into<Box<str>>) -> MmdbReader
Set the preferred language code used to resolve localised names
(default "en"). This is the lookup key into the database’s localised
names maps (e.g. "en", "de", "pt-BR").
pub fn lookup(&self, ip: IpAddr) -> Option<GeoLocationRef<'_>>
pub fn lookup(&self, ip: IpAddr) -> Option<GeoLocationRef<'_>>
Look up ip, returning a zero-copy view of its record if present.
IPv4-mapped IPv6 inputs are canonicalised to IPv4 first. Looking up an
IPv4 address in an IPv6 database traverses the ::/96 range.
This is best-effort: a structurally corrupt database encountered mid
lookup yields None, indistinguishable from a legitimate miss. Use
Self::try_lookup when you need to observe corruption.
pub fn try_lookup(
&self,
ip: IpAddr,
) -> Result<Option<GeoLocationRef<'_>>, GeoIpError>
pub fn try_lookup( &self, ip: IpAddr, ) -> Result<Option<GeoLocationRef<'_>>, GeoIpError>
Like Self::lookup, but reports database corruption encountered
during traversal as a GeoIpError instead of collapsing it to None.
§Errors
Returns GeoIpError::Corrupt if the search tree is structurally
invalid for ip.
Trait Implementations§
§impl Clone for MmdbReader
impl Clone for MmdbReader
§fn clone(&self) -> MmdbReader
fn clone(&self) -> MmdbReader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for MmdbReader
impl RefUnwindSafe for MmdbReader
impl Send for MmdbReader
impl Sync for MmdbReader
impl Unpin for MmdbReader
impl UnsafeUnpin for MmdbReader
impl UnwindSafe for MmdbReader
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer