From 4859108951ae05a7a02f80693e6cebf591301fea Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 31 Mar 2022 01:34:37 +0100 Subject: [PATCH] RawToken: Replace constructor with a From impl No functional change. Signed-off-by: Ian Jackson --- src/global.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/global.rs b/src/global.rs index 7587ed92..fe5feb8e 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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 for RawToken { - fn borrow(&self) -> &RawTokenVal { RawTokenVal::from_str(&self.0) } + fn borrow(&self) -> &RawTokenVal { (&*self.0).into() } } impl Debug for RawTokenVal { -- 2.30.2