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