feat(core): allow optionally disabling expensive codegen

This commit is contained in:
TotallyNot 2025-04-27 15:23:52 +02:00
parent 26043ac318
commit 4dd4fd37d4
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
7 changed files with 32 additions and 84 deletions

View file

@ -1,12 +1,7 @@
use bon::Builder;
use bytes::Bytes;
use http::StatusCode;
use crate::{
executor::Executor,
models::{FactionChainsResponse, FactionId},
};
#[cfg(feature = "requests")]
pub mod models;
#[derive(Default)]
@ -40,65 +35,5 @@ pub trait IntoRequest: Send {
fn into_request(self) -> ApiRequest<Self::Discriminant>;
}
pub struct FactionScope<'e, E>(&'e E)
where
E: Executor;
impl<E> FactionScope<'_, E>
where
E: Executor,
{
pub async fn chains_for_id<S>(
&self,
id: FactionId,
builder: impl FnOnce(
FactionChainsRequestBuilder<faction_chains_request_builder::Empty>,
) -> FactionChainsRequestBuilder<S>,
) -> Result<FactionChainsResponse, E::Error>
where
S: faction_chains_request_builder::IsComplete,
{
let r = builder(FactionChainsRequest::with_id(id)).build();
self.0.fetch(r).await
}
}
#[derive(Builder)]
#[builder(start_fn = with_id)]
pub struct FactionChainsRequest {
#[builder(start_fn)]
pub id: FactionId,
pub limit: Option<usize>,
}
impl IntoRequest for FactionChainsRequest {
type Discriminant = FactionId;
type Response = FactionChainsResponse;
fn into_request(self) -> ApiRequest<Self::Discriminant> {
ApiRequest {
disriminant: self.id,
path: format!("/faction/{}/chains", self.id),
parameters: self
.limit
.into_iter()
.map(|l| ("limit", l.to_string()))
.collect(),
}
}
}
#[cfg(test)]
mod test {
use crate::executor::ReqwestClient;
use super::*;
#[tokio::test]
async fn test_request() {
let client = ReqwestClient::new("nAYRXaoqzBAGalWt");
let r = models::TornItemsForIdsRequest::builder("1".to_owned()).build();
client.fetch(r).await.unwrap();
}
}
mod test {}