From: Ian Jackson Date: Sun, 21 Feb 2021 23:37:35 +0000 (+0000) Subject: Use lots of deref_to_field X-Git-Tag: otter-0.4.0~385 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9457a30af9e55ed7831e119145aef567ab2097f1;p=otter.git Use lots of deref_to_field Signed-off-by: Ian Jackson --- diff --git a/src/accounts.rs b/src/accounts.rs index 36031b3c..a04a4847 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -215,10 +215,8 @@ impl FromStr for AccountName { //---------- AccessRecord ---------- -impl Deref for AccessRecord { - type Target = Arc; - fn deref(&self) -> &Self::Target { return &self.0 } -} +// No DerefMut, to make sure we save properly etc. +deref_to_field!{AccessRecord, Arc, 0} impl AccessRecord { pub fn new_unset() -> Self{ Self( Arc::new(PlayerAccessUnset) ) } diff --git a/src/global.rs b/src/global.rs index 04f05837..cad764ea 100644 --- a/src/global.rs +++ b/src/global.rs @@ -40,6 +40,7 @@ pub struct InstanceRef (Arc>); #[derive(Debug,Clone,Serialize,Deserialize,Default)] #[serde(transparent)] pub struct LinksTable(pub EnumMap>); +deref_to_field_mut!{LinksTable, EnumMap>, 0} pub struct Instance { pub name: Arc, @@ -485,14 +486,6 @@ impl From<(LinkKind, &str)> for Html { } } -impl Deref for LinksTable { - type Target = EnumMap>; - fn deref(&self) -> &Self::Target { &self.0 } -} -impl DerefMut for LinksTable { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - impl From<&LinksTable> for Html { fn from(links: &LinksTable) -> Html { let mut s = links.iter() @@ -1265,10 +1258,8 @@ impl PiecesLoaded { // ---------- gamestate pieces table ---------- -impl Deref for Pieces { - type Target = ActualPieces; - fn deref(&self) -> &ActualPieces { &self.0 } -} +// No DerefMut to make sure we send updates, save, etc. +deref_to_field!{Pieces, ActualPieces, 0} impl Pieces { pub fn get_mut(&mut self, piece: PieceId) -> Option<&mut PieceState> { diff --git a/src/sse.rs b/src/sse.rs index ab4af119..4cb93bb5 100644 --- a/src/sse.rs +++ b/src/sse.rs @@ -37,11 +37,7 @@ struct UpdateReader { ending_send: Option>>, init_confirmation_send: iter::Once<()>, } - -impl Deref for UpdateReader { - type Target = UpdateReaderWN; - fn deref(&self) -> &UpdateReaderWN { &self.wn } -} +deref_to_field!{UpdateReader, UpdateReaderWN, wn} // no DerefMut #[derive(Error,Debug)] #[error("WouldBlock error misreported!")] diff --git a/wdriver.rs b/wdriver.rs index 8eb97c6e..67884498 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -29,11 +29,7 @@ pub struct Opts { #[structopt(long="--geckodriver-args", default_value="")] geckodriver_args: String, } - -impl Deref for Opts { - type Target = apitest::Opts; - fn deref(&self) -> &Self::Target { &self.at } -} +deref_to_field!{Opts, apitest::Opts, at} impl AsRef for Opts { fn as_ref(&self) -> &apitest::Opts { &self.at } }