DDApi

Struct DDApi 

Source
pub struct DDApi { /* private fields */ }

Implementations§

Source§

impl DDApi

Source

pub fn new() -> Self

Creates a new DDApi instance with default settings

§Examples
use ddapi_rs::prelude::*;

let api = DDApi::new();
Source

pub fn new_with_client(client: Client) -> Self

Creates a new DDApi instance with a custom HTTP client

This allows you to configure your own client with custom timeouts, headers, or other settings.

§Arguments
  • client - A pre-configured reqwest::Client instance
§Examples
use ddapi_rs::prelude::*;
use reqwest::Client;

let client = Client::builder()
    .timeout(std::time::Duration::from_secs(10))
    .build()
    .unwrap();
let api = DDApi::new_with_client(client);
Source

pub async fn _generator<T>(&self, url: &str) -> Result<T>
where T: DeserializeOwned + Send + Sync + 'static,

Executes an API request and deserializes the JSON response

This method handles API requests and automatically deserializes the JSON response into the specified type. The caching behavior is determined by the cache feature flag.

§Type Parameters
  • T - The type to deserialize the response into. Must implement DeserializeOwned + Send + Sync + 'static
§Arguments
  • url - The API endpoint URL to request
§Returns
§Returns

Result<T> containing the deserialized data on success, or an error on failure

Source

pub async fn _generator_no_cache<T>(&self, url: &str) -> Result<T>

Executes an API request without caching

Always fetches fresh data from the API, bypassing any cache.

§Type Parameters
  • T - The type to deserialize the response into
§Arguments
  • url - The API endpoint URL to request
§Returns

Returns Result<T> with freshly fetched deserialized data

Trait Implementations§

Source§

impl Clone for DDApi

Source§

fn clone(&self) -> DDApi

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 DDnetApi for DDApi

Source§

async fn master(&self) -> Result<Master>

Fetches server list from the default master server

Returns a list of game servers from the primary master server (master1.ddnet.org).

§Examples
use ddapi_rs::prelude::*;

let api = DDApi::new();
let master = api.master().await?;
println!("Found {} servers", master.servers.len());
Source§

async fn custom_master(&self, master: MasterServer) -> Result<Master>

Fetches server list from a specific master server

Allows selecting which master server to query. DDNet has multiple master servers for redundancy and load distribution.

§Arguments
  • master - The master server to query (MasterServer::One, MasterServer::Two, etc.)
§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
// Use secondary master server as fallback
let master = api.custom_master(MasterServer::Two).await?;
Source§

async fn skins(&self) -> Result<DDSkins>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let skins: DDSkins = api.skins().await?;
println!("Found {} available skins", skins.skins.len());
for skin in skins.skins {
    println!("Skin: {} by {}", skin.name, skin.creator);
}
Source§

async fn player(&self, player: &str) -> Result<Player>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let player: Player = api.player("nameless tee").await?;
println!("{}: {}", player.player, player.points.points.unwrap_or(0));
Source§

async fn query(&self, player: &str) -> Result<Vec<Query>>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let query: Vec<Query> = api.query("nameless tee").await?;
for player in &query {
    println!("{}: {}", player.name, player.points);
}
Source§

async fn query_map(&self, map: &str) -> Result<Vec<QueryMap>>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let query: Vec<QueryMap> = api.query_map("multi").await?;
for map in &query {
    println!("{}: {} | {}", map.name, map.mapper, map.r#type);
}
Source§

async fn query_mapper(&self, player: &str) -> Result<Vec<QueryMapper>>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let query: Vec<QueryMapper> = api.query_mapper("Ao").await?;
for player in &query {
    println!("{}: {}", player.mapper, player.num_maps);
}
Source§

async fn map(&self, map: &str) -> Result<Map>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let map: Map = api.map("Fox").await?;
println!("{}: {}", map.mapper, map.web_preview);
Source§

async fn releases_map(&self) -> Result<Vec<ReleasesMaps>>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let maps: Vec<ReleasesMaps> = api.releases_map().await?;
for map in &maps {
    println!("{}: {} | {}", map.name, map.mapper, map.r#type);
}
Source§

async fn status(&self) -> Result<Status>

§Examples
use ddapi_rs::prelude::*;
use ddapi_rs::prelude::ddnet::*;

let api = DDApi::new();
let status: Status = api.status().await?;
for data in &status.servers {
    println!("{}: {} | {}", data.name, data.location, data.host);
}
Source§

impl Default for DDApi

Source§

fn default() -> DDApi

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

Auto Trait Implementations§

§

impl Freeze for DDApi

§

impl !RefUnwindSafe for DDApi

§

impl Send for DDApi

§

impl Sync for DDApi

§

impl Unpin for DDApi

§

impl !UnwindSafe for DDApi

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