pub struct Client { /* private fields */ }Expand description
The character service’s client.
Implementations§
Source§impl Client
impl Client
Sourcepub const MAX_RETRIES: usize = 5
pub const MAX_RETRIES: usize = 5
How many times Client::modify re-applies a change after losing a
race with another writer before giving up.
Sourcepub fn new(base_url: impl Into<String>) -> Self
pub fn new(base_url: impl Into<String>) -> Self
A client for the character service at base_url, without a token.
Sourcepub fn with_token(self, token: &str) -> Self
pub fn with_token(self, token: &str) -> Self
Sends token (from auth::AuthClient::login) with every request.
Sourcepub async fn list(&self) -> Result<Vec<CharacterSummary>, ClientError>
pub async fn list(&self) -> Result<Vec<CharacterSummary>, ClientError>
The campaign’s characters.
Sourcepub async fn create(
&self,
sheet: &CharacterSheet,
) -> Result<Character, ClientError>
pub async fn create( &self, sheet: &CharacterSheet, ) -> Result<Character, ClientError>
Creates a character from sheet.
Sourcepub async fn replace(
&self,
id: Uuid,
version: u64,
sheet: &CharacterSheet,
) -> Result<Character, ClientError>
pub async fn replace( &self, id: Uuid, version: u64, sheet: &CharacterSheet, ) -> Result<Character, ClientError>
Replaces the sheet, failing with ClientError::Stale if the server’s
copy is no longer at version.
Sourcepub async fn modify<E>(
&self,
id: Uuid,
change: impl FnMut(&mut CharacterSheet) -> Result<(), E>,
) -> Result<Character, E>where
E: From<ClientError>,
pub async fn modify<E>(
&self,
id: Uuid,
change: impl FnMut(&mut CharacterSheet) -> Result<(), E>,
) -> Result<Character, E>where
E: From<ClientError>,
Fetches the character, applies change and saves it. If someone else
saved in between, change is re-applied to their newer copy, so
edits merge instead of overwriting each other. change may therefore
run more than once and should only express the caller’s intent
(“set max HP to 50”), not depend on the previous value being fixed.
Sourcepub async fn set_owners(
&self,
id: Uuid,
owners: &[String],
) -> Result<Character, ClientError>
pub async fn set_owners( &self, id: Uuid, owners: &[String], ) -> Result<Character, ClientError>
Sets which player devices play the character, by key (DM devices only).
Sourcepub async fn act(
&self,
id: Uuid,
action: &CharacterAction,
) -> Result<Character, ClientError>
pub async fn act( &self, id: Uuid, action: &CharacterAction, ) -> Result<Character, ClientError>
Applies an action to a character.
Sourcepub async fn act_once(
&self,
id: Uuid,
action: &CharacterAction,
key: Uuid,
) -> Result<Character, ClientError>
pub async fn act_once( &self, id: Uuid, action: &CharacterAction, key: Uuid, ) -> Result<Character, ClientError>
Like Client::act, but only once per key: sending it again
with the same key changes nothing, so it’s safe to retry.