Struct UserAgentDatabase
pub struct UserAgentDatabase { /* private fields */ }
Expand description
Reference implementation of a UserAgentProvider
.
It stores the profiles and several indices in memory
to quickly find a profile by User-Agent header value string,
UserAgentKind
, PlatformKind
and DeviceKind
.
Where needed it makes use of market share data to select a random profile or subset.
See UserAgentProvider
for more details.
Implementations§
§impl UserAgentDatabase
impl UserAgentDatabase
pub fn embedded() -> UserAgentDatabase
pub fn embedded() -> UserAgentDatabase
Load the profiles embedded with the rama-ua crate.
This function is only available if the embed-profiles
feature is enabled.
pub fn disable_unknown_user_agent_data(self, disable: bool) -> UserAgentDatabase
pub fn disable_unknown_user_agent_data(self, disable: bool) -> UserAgentDatabase
Disabling this option (disable = true) means here that in case
you try to use UserAgentDatabase::get
with a UserAgent
containing no match (not even a platform or device), that it the database
will return None
instead of returning a global-random (market-based)
UserAgentProfile
, which it would do by default.
pub fn set_disable_unknown_user_agent_data(
&mut self,
disable: bool,
) -> &mut UserAgentDatabase
pub fn set_disable_unknown_user_agent_data( &mut self, disable: bool, ) -> &mut UserAgentDatabase
See [disable_unknown_user_agent_data
], this is the non-consuming version.
pub fn iter_ua_str(&self) -> impl Iterator<Item = &str>
pub fn iter_ua_str(&self) -> impl Iterator<Item = &str>
Iterate over the User-Agent header value strings in the database.
pub fn iter_ua_kind(&self) -> impl Iterator<Item = &UserAgentKind>
pub fn iter_ua_kind(&self) -> impl Iterator<Item = &UserAgentKind>
Iterate over the available UserAgentKind
s in the database.
pub fn iter_platform(&self) -> impl Iterator<Item = &PlatformKind>
pub fn iter_platform(&self) -> impl Iterator<Item = &PlatformKind>
Iterate over the available PlatformKind
s in the database.
pub fn iter_device(&self) -> impl Iterator<Item = &DeviceKind>
pub fn iter_device(&self) -> impl Iterator<Item = &DeviceKind>
Iterate over the available DeviceKind
s in the database.
pub fn insert(&mut self, profile: UserAgentProfile)
pub fn insert(&mut self, profile: UserAgentProfile)
Insert a new UserAgentProfile
into the database,
ensuring to also index it by User-Agent header value string,
UserAgentKind
, PlatformKind
and DeviceKind
.
pub fn rnd(&self) -> Option<&UserAgentProfile>
pub fn rnd(&self) -> Option<&UserAgentProfile>
Select a random UserAgentProfile
from the database.
It makes use of global market share data to select a random profile.
pub fn get_exact_header_str(&self, ua: &str) -> Option<&UserAgentProfile>
pub fn get_exact_header_str(&self, ua: &str) -> Option<&UserAgentProfile>
Get a UserAgentProfile
from the database by an UserAgent
header string
pub fn get(&self, ua: &UserAgent) -> Option<&UserAgentProfile>
pub fn get(&self, ua: &UserAgent) -> Option<&UserAgentProfile>
Get a UserAgentProfile
from the database by UserAgent
.
It first tries to find the profile by User-Agent header value string,
if not found it then makes use of UserAgentKind
, PlatformKind
and DeviceKind
to find a profile.
pub fn iter(&self) -> impl Iterator<Item = &UserAgentProfile>
pub fn iter(&self) -> impl Iterator<Item = &UserAgentProfile>
Iterate over all UserAgentProfile
s in the database.
Trait Implementations§
§impl Debug for UserAgentDatabase
impl Debug for UserAgentDatabase
§impl Default for UserAgentDatabase
impl Default for UserAgentDatabase
§fn default() -> UserAgentDatabase
fn default() -> UserAgentDatabase
§impl FromIterator<UserAgentProfile> for UserAgentDatabase
impl FromIterator<UserAgentProfile> for UserAgentDatabase
§fn from_iter<T>(iter: T) -> UserAgentDatabasewhere
T: IntoIterator<Item = UserAgentProfile>,
fn from_iter<T>(iter: T) -> UserAgentDatabasewhere
T: IntoIterator<Item = UserAgentProfile>,
§impl UserAgentProvider for UserAgentDatabase
impl UserAgentProvider for UserAgentDatabase
§fn select_user_agent_profile(&self, ctx: &Context) -> Option<&UserAgentProfile>
fn select_user_agent_profile(&self, ctx: &Context) -> Option<&UserAgentProfile>
Auto Trait Implementations§
impl Freeze for UserAgentDatabase
impl RefUnwindSafe for UserAgentDatabase
impl Send for UserAgentDatabase
impl Sync for UserAgentDatabase
impl Unpin for UserAgentDatabase
impl UnwindSafe for UserAgentDatabase
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<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> 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