From 26216a295f71d5ef97fb1ea17d4d57a9e89f1c86 Mon Sep 17 00:00:00 2001
From: Evan Hemsley <evan@moonside.games>
Date: Sun, 22 Mar 2020 14:20:22 -0700
Subject: [PATCH] singular message reads are ref readonly

---
 encompass-cs/Collections/MessageStore.cs      | 4 ++--
 encompass-cs/Collections/TypedMessageStore.cs | 4 ++--
 encompass-cs/Engine.cs                        | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/encompass-cs/Collections/MessageStore.cs b/encompass-cs/Collections/MessageStore.cs
index 632cfd3..8495966 100644
--- a/encompass-cs/Collections/MessageStore.cs
+++ b/encompass-cs/Collections/MessageStore.cs
@@ -33,9 +33,9 @@ namespace Encompass
             Lookup<TMessage>().AddIgnoringTimeDilation(message, time);
         }
 
-        public TMessage First<TMessage>() where TMessage : struct, IMessage
+        public ref readonly TMessage First<TMessage>() where TMessage : struct, IMessage
         {
-            return Lookup<TMessage>().First();
+            return ref Lookup<TMessage>().First();
         }
 
         public Span<TMessage> All<TMessage>() where TMessage : struct, IMessage
diff --git a/encompass-cs/Collections/TypedMessageStore.cs b/encompass-cs/Collections/TypedMessageStore.cs
index 3e8d815..f5bd150 100644
--- a/encompass-cs/Collections/TypedMessageStore.cs
+++ b/encompass-cs/Collections/TypedMessageStore.cs
@@ -78,9 +78,9 @@ namespace Encompass
             _delayedStoreIgnoringTimeDilation.Add((message, time));
         }
 
-        public TMessage First()
+        public ref readonly TMessage First()
         {
-            return _store[0];
+            return ref _store[0];
         }
 
         public bool Any()
diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs
index d98fe87..b0aa6e5 100644
--- a/encompass-cs/Engine.cs
+++ b/encompass-cs/Engine.cs
@@ -731,10 +731,10 @@ namespace Encompass
         /// Efficiently reads a single Message of a given type that references a given Entity.
         /// It is recommended to use this method in conjunction with SomeMessageWithEntity to prevent errors.
         /// </summary>
-        protected TMessage ReadMessageWithEntity<TMessage>(Entity entity) where TMessage : struct, IMessage, IHasEntity
+        protected ref readonly TMessage ReadMessageWithEntity<TMessage>(Entity entity) where TMessage : struct, IMessage, IHasEntity
         {
             CheckMessageRead<TMessage>();
-            return _messageManager.WithEntitySingular<TMessage>(entity.ID);
+            return ref _messageManager.WithEntitySingular<TMessage>(entity.ID);
         }
 
         /// <summary>