From 9c647bb7cef09f0323f19b38b90c685f33949420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 11 Dec 2020 12:24:05 +0200 Subject: [PATCH] impl WordSplitter for Box where T: WordSplitter This allows more generic use, and e.g. as Box. --- src/splitting.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/splitting.rs b/src/splitting.rs index fbb06396..01e905f3 100644 --- a/src/splitting.rs +++ b/src/splitting.rs @@ -30,20 +30,13 @@ pub trait WordSplitter: std::fmt::Debug { fn split_points(&self, word: &str) -> Vec; } -impl WordSplitter for Box { +impl WordSplitter for Box { fn split_points(&self, word: &str) -> Vec { use std::ops::Deref; self.deref().split_points(word) } } -/* Alternative, also adds impls for specific Box i.e. Box -impl WordSplitter for Box { - fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)> { - use std::ops::Deref; - self.deref().split(word) - } -} -*/ + impl WordSplitter for &T { fn split_points(&self, word: &str) -> Vec { (*self).split_points(word)