From b469f8b1e360f1169e9a2d4e6de382c63502c72b Mon Sep 17 00:00:00 2001 From: stuebinm Date: Fri, 3 Sep 2021 00:02:33 +0200 Subject: somewhat pointless generalisation of a type signature There's no real reason for this other than that I wanted to know if abstracting over &[T] -> T and &str -> String etc. was possible. --- isabelle-unicode/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/isabelle-unicode/src/lib.rs b/isabelle-unicode/src/lib.rs index 8394e57..30a7cec 100644 --- a/isabelle-unicode/src/lib.rs +++ b/isabelle-unicode/src/lib.rs @@ -1,13 +1,15 @@ symbolmacro::make_symbols!(); -// TODO: is it possible to be polymorphic over slice types here? pub trait PrettyUnicode { - fn to_pretty_unicode(self) -> Option; + type Owned: core::borrow::Borrow; + fn to_pretty_unicode(&self) -> Option; } -impl PrettyUnicode for &str { - fn to_pretty_unicode(self) -> Option { +impl PrettyUnicode for str { + type Owned = String; + + fn to_pretty_unicode(&self) -> Option { // split at escape sequences let mut chunks = self.split("\\<"); @@ -30,7 +32,7 @@ impl PrettyUnicode for &str { // how much of the rest do we need? let offset = ident? - .len() + .len() + 1; Some((symbol, &chunk[offset..])) }) -- cgit v1.2.3