mirror of
https://codeberg.org/demostf/api-client.git
synced 2026-06-03 08:34:15 +02:00
minor cleanup
This commit is contained in:
parent
be065cdb1b
commit
91b3f879c9
2 changed files with 17 additions and 9 deletions
|
|
@ -8,6 +8,8 @@ license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/demostf/api-client"
|
repository = "https://github.com/demostf/api-client"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
exclude = [ "tests/data/gully.dem" ]
|
exclude = [ "tests/data/gully.dem" ]
|
||||||
|
keywords = ["tf2", "demo"]
|
||||||
|
categories = ["api-bindings"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
|
||||||
24
src/lib.rs
24
src/lib.rs
|
|
@ -59,11 +59,11 @@ pub struct Demo {
|
||||||
impl Demo {
|
impl Demo {
|
||||||
/// Return either the stored players info or get the players from the api
|
/// Return either the stored players info or get the players from the api
|
||||||
pub async fn get_players<'a>(&'a self, client: &ApiClient) -> Result<Cow<'a, [Player]>, Error> {
|
pub async fn get_players<'a>(&'a self, client: &ApiClient) -> Result<Cow<'a, [Player]>, Error> {
|
||||||
if !self.players.is_empty() {
|
if self.players.is_empty() {
|
||||||
Ok(Cow::Borrowed(self.players.as_slice()))
|
|
||||||
} else {
|
|
||||||
let demo = client.get(self.id).await?;
|
let demo = client.get(self.id).await?;
|
||||||
Ok(Cow::Owned(demo.players))
|
Ok(Cow::Owned(demo.players))
|
||||||
|
} else {
|
||||||
|
Ok(Cow::Borrowed(self.players.as_slice()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,8 +92,7 @@ pub enum UserRef {
|
||||||
impl UserRef {
|
impl UserRef {
|
||||||
pub fn id(&self) -> u32 {
|
pub fn id(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
UserRef::Id(id) => *id,
|
UserRef::Id(id) | UserRef::User(User { id, .. }) => *id,
|
||||||
UserRef::User(User { id, .. }) => *id,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,20 +282,23 @@ impl Serialize for PlayerList {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListParams {
|
impl ListParams {
|
||||||
pub fn with_backend(self, backend: impl ToString) -> Self {
|
#[must_use]
|
||||||
|
pub fn with_backend(self, backend: impl Into<String>) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
backend: Some(backend.to_string()),
|
backend: Some(backend.into()),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_map(self, map: impl ToString) -> Self {
|
#[must_use]
|
||||||
|
pub fn with_map(self, map: impl Into<String>) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
map: Some(map.to_string()),
|
map: Some(map.into()),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn with_players<T: Into<SteamID>, I: IntoIterator<Item = T>>(self, players: I) -> Self {
|
pub fn with_players<T: Into<SteamID>, I: IntoIterator<Item = T>>(self, players: I) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
players: PlayerList(players.into_iter().map(Into::into).collect()),
|
players: PlayerList(players.into_iter().map(Into::into).collect()),
|
||||||
|
|
@ -304,6 +306,7 @@ impl ListParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn with_type(self, ty: GameType) -> Self {
|
pub fn with_type(self, ty: GameType) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
ty: Some(ty),
|
ty: Some(ty),
|
||||||
|
|
@ -311,6 +314,7 @@ impl ListParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn with_before(self, before: OffsetDateTime) -> Self {
|
pub fn with_before(self, before: OffsetDateTime) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
before: Some(before),
|
before: Some(before),
|
||||||
|
|
@ -318,6 +322,7 @@ impl ListParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn with_after(self, after: OffsetDateTime) -> Self {
|
pub fn with_after(self, after: OffsetDateTime) -> Self {
|
||||||
ListParams {
|
ListParams {
|
||||||
after: Some(after),
|
after: Some(after),
|
||||||
|
|
@ -325,6 +330,7 @@ impl ListParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn with_order(self, order: ListOrder) -> Self {
|
pub fn with_order(self, order: ListOrder) -> Self {
|
||||||
ListParams { order, ..self }
|
ListParams { order, ..self }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue