Rename 'or_default' to 'extract'. Better meaning.
This commit is contained in:
parent
5ea5d627bb
commit
6c1d19aa44
|
@ -14,17 +14,20 @@ pub mod api {
|
|||
//include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.api.rs"));
|
||||
tonic::include_proto!("models.proto.cofd.api");
|
||||
|
||||
/// Trait to extract CharacterIdentifier while avoiding clone. The
|
||||
/// character identifier is extracted out of the Option, leaving
|
||||
/// None in its place.
|
||||
/// Trait to take ownership of CharacterIdentifiers while avoiding
|
||||
/// clone. The identifier is extracted out of the type, leaving a
|
||||
/// default value in its place.
|
||||
pub trait DefaultCharacterIdentifier {
|
||||
/// Extract the CharacterIdentifier from the containing type,
|
||||
/// leaving behind a default value.
|
||||
fn or_default(&mut self) -> CharacterIdentifier;
|
||||
/// Take ownership of a CharacterIdentifier by taking it out
|
||||
/// of the containing type, leaving behind a default value
|
||||
/// (None, in the case of Option) in its place.
|
||||
fn extract(&mut self) -> CharacterIdentifier;
|
||||
}
|
||||
|
||||
impl DefaultCharacterIdentifier for Option<CharacterIdentifier> {
|
||||
fn or_default(&mut self) -> CharacterIdentifier {
|
||||
/// Extract the identifier, or a default one if the identifier
|
||||
/// is not specified for some reason.
|
||||
fn extract(&mut self) -> CharacterIdentifier {
|
||||
self.take().unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ pub(super) async fn update_basic_info<'a>(
|
|||
conn: TenebrousDbConn<'_>,
|
||||
logged_in_user: Option<&User>,
|
||||
) -> Result<Proto<ApiResult>, Error> {
|
||||
let id = req.id.or_default();
|
||||
let id = req.id.extract();
|
||||
let mut character = load_character(&conn, logged_in_user, &id.owner, id.character_id).await?;
|
||||
let mut sheet: CofdSheet = character.try_deserialize()?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue