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

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

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

See [disable_unknown_user_agent_data], this is the non-consuming version.

pub fn len(&self) -> usize

Get the number of profiles in the database.

pub fn is_empty(&self) -> bool

Check if the database is empty.

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>

Iterate over the available UserAgentKinds in the database.

pub fn iter_platform(&self) -> impl Iterator<Item = &PlatformKind>

Iterate over the available PlatformKinds in the database.

pub fn iter_device(&self) -> impl Iterator<Item = &DeviceKind>

Iterate over the available DeviceKinds in the database.

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>

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>

Get a UserAgentProfile from the database by an UserAgent header string

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>

Iterate over all UserAgentProfiles in the database.

Trait Implementations§

§

impl Debug for UserAgentDatabase

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for UserAgentDatabase

§

fn default() -> UserAgentDatabase

Returns the “default value” for a type. Read more
§

impl FromIterator<UserAgentProfile> for UserAgentDatabase

§

fn from_iter<T>(iter: T) -> UserAgentDatabase
where T: IntoIterator<Item = UserAgentProfile>,

Creates a value from an iterator. Read more
§

impl UserAgentProvider for UserAgentDatabase

§

fn select_user_agent_profile(&self, ctx: &Context) -> Option<&UserAgentProfile>

Selects a user agent profile based on the current context.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> RamaInto<U> for T
where U: RamaFrom<T>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaInto<U> for T
where U: RamaFrom<T>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaTryInto<U> for T
where U: RamaTryFrom<T>,

§

type Error = <U as RamaTryFrom<T>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T>>::Error>

§

impl<T, U> RamaTryInto<U> for T
where U: RamaTryFrom<T>,

§

type Error = <U as RamaTryFrom<T>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T>>::Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,