chiark / gitweb /
RawToken: Replace constructor with a From impl
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 00:34:37 +0000 (01:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 00:34:37 +0000 (01:34 +0100)
No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/global.rs

index 7587ed9245f13878de101cf565eb5dc1ce2a4ed7..fe5feb8edcaa968cff5a5c9acafeccb191e1dba9 100644 (file)
@@ -258,15 +258,15 @@ const PRIVATE_Y: PrivateCaller = PrivateCaller(());
 
 // ========== implementations ==========
 
-impl RawTokenVal {
+impl<'s> From<&'s str> for &'s RawTokenVal {
   // str is [u8] with a funny hat on, so &str is pointer + byte count.
   // nomicon says &SomeStruct([T]) is pointer plus number of elements.
   // So &str and &SomeStruct(str) have the same layout
-  pub fn from_str(s: &str) -> &RawTokenVal { unsafe { mem::transmute(s) } }
+  fn from(s: &str) -> &RawTokenVal { unsafe { mem::transmute(s) } }
 }
 
 impl Borrow<RawTokenVal> for RawToken {
-  fn borrow(&self) -> &RawTokenVal { RawTokenVal::from_str(&self.0) }
+  fn borrow(&self) -> &RawTokenVal { (&*self.0).into() }
 }
 
 impl Debug for RawTokenVal {