From: Ian Jackson Date: Thu, 31 Mar 2022 00:34:37 +0000 (+0100) Subject: RawToken: Replace constructor with a From impl X-Git-Tag: otter-1.0.0~47 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4859108951ae05a7a02f80693e6cebf591301fea;p=otter.git RawToken: Replace constructor with a From impl No functional change. Signed-off-by: Ian Jackson --- 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 {