Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An async client for the UK Police API.

§Example

let client = uk_police_api::Client::new();
let forces = client.forces().await?;

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Source

pub fn from_http_client(http: Client) -> Self

Creates a client with a pre-configured reqwest::Client.

Use this to customize timeouts, headers, proxies, or any other HTTP behaviour.

§Example
let http = reqwest::Client::builder()
    .timeout(std::time::Duration::from_secs(10))
    .build()
    .unwrap();
let client = uk_police_api::Client::from_http_client(http);
Source

pub async fn forces(&self) -> Result<Vec<Force>, Error>

Returns a list of all police forces.

Source

pub async fn force(&self, id: &str) -> Result<ForceDetail, Error>

Returns details for a specific police force.

Source

pub async fn crime_categories( &self, date: Option<&str>, ) -> Result<Vec<CrimeCategory>, Error>

Returns a list of crime categories. Optionally filtered by date (format: YYYY-MM).

Source

pub async fn street_level_crimes( &self, category: &str, area: &Area, date: Option<&str>, ) -> Result<Vec<Crime>, Error>

Returns street-level crimes within a given area.

§Arguments
  • category - Crime category slug (e.g. “all-crime”, “burglary”). See Client::crime_categories.
  • area - Either a point (1 mile radius) or a custom polygon.
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn street_level_outcomes( &self, area: &Area, date: Option<&str>, ) -> Result<Vec<Outcome>, Error>

Returns street-level outcomes at a given location.

§Arguments
  • area - A point (1 mile radius), custom polygon, or specific location ID.
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn crime_last_updated(&self) -> Result<CrimeLastUpdated, Error>

Returns the date when crime data was last updated.

Source

pub async fn senior_officers( &self, force_id: &str, ) -> Result<Vec<SeniorOfficer>, Error>

Returns a list of senior officers for a given force.

Source

pub async fn crimes_at_location( &self, location_id: u64, date: Option<&str>, ) -> Result<Vec<Crime>, Error>

Returns crimes at a specific location.

§Arguments
  • location_id - A location ID (from a street’s id field).
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn crimes_no_location( &self, category: &str, force: &str, date: Option<&str>, ) -> Result<Vec<Crime>, Error>

Returns crimes that could not be mapped to a location.

§Arguments
  • category - Crime category slug (e.g. “all-crime”). See Client::crime_categories.
  • force - Force identifier (e.g. “metropolitan”).
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn outcomes_for_crime( &self, persistent_id: &str, ) -> Result<CrimeOutcomes, Error>

Returns all outcomes for a specific crime.

§Arguments
  • persistent_id - The 64-character crime identifier.
Source

pub async fn neighbourhoods( &self, force_id: &str, ) -> Result<Vec<Neighbourhood>, Error>

Returns a list of neighbourhoods for a force.

Source

pub async fn neighbourhood( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<NeighbourhoodDetail, Error>

Returns details for a specific neighbourhood.

Source

pub async fn neighbourhood_boundary( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<LatLng>, Error>

Returns the boundary of a neighbourhood as a list of lat/lng pairs.

Source

pub async fn neighbourhood_team( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<SeniorOfficer>, Error>

Returns the policing team for a neighbourhood.

Source

pub async fn neighbourhood_events( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<NeighbourhoodEvent>, Error>

Returns events for a neighbourhood.

Source

pub async fn neighbourhood_priorities( &self, force_id: &str, neighbourhood_id: &str, ) -> Result<Vec<NeighbourhoodPriority>, Error>

Returns policing priorities for a neighbourhood.

Source

pub async fn locate_neighbourhood( &self, lat: f64, lng: f64, ) -> Result<LocateNeighbourhoodResult, Error>

Locates the neighbourhood policing team responsible for a given point.

Source

pub async fn stops_street( &self, area: &Area, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>

Returns stop and searches within a given area.

§Arguments
  • area - A point (1 mile radius) or custom polygon.
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn stops_at_location( &self, location_id: u64, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>

Returns stop and searches at a specific location.

§Arguments
  • location_id - A location ID (from a street’s id field).
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn stops_no_location( &self, force: &str, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>

Returns stop and searches that could not be mapped to a location.

§Arguments
  • force - Force identifier (e.g. “metropolitan”).
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.
Source

pub async fn stops_force( &self, force: &str, date: Option<&str>, ) -> Result<Vec<StopAndSearch>, Error>

Returns stop and searches reported by a force.

§Arguments
  • force - Force identifier (e.g. “metropolitan”).
  • date - Optional month filter (format: YYYY-MM). Defaults to the latest available.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

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

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

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

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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