summaryrefslogtreecommitdiff
path: root/isabelle-unicode
diff options
context:
space:
mode:
authorstuebinm2021-09-03 00:02:33 +0200
committerstuebinm2021-09-03 00:02:33 +0200
commitb469f8b1e360f1169e9a2d4e6de382c63502c72b (patch)
treee1ea733925b26030188050c3ebb460e375a927fb /isabelle-unicode
parentad514f56b6cda288e605c44990ef16d30e6dee53 (diff)
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.
Diffstat (limited to 'isabelle-unicode')
-rw-r--r--isabelle-unicode/src/lib.rs12
1 files 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<String>;
+ type Owned: core::borrow::Borrow<Self>;
+ fn to_pretty_unicode(&self) -> Option<Self::Owned>;
}
-impl PrettyUnicode for &str {
- fn to_pretty_unicode(self) -> Option<String> {
+impl PrettyUnicode for str {
+ type Owned = String;
+
+ fn to_pretty_unicode(&self) -> Option<Self::Owned> {
// 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..]))
})