@@ -211,13 +211,56 @@ impl Fragments {
211211 }
212212}
213213
214+ /// Newtype wrapper for table names.
215+ ///
216+ /// Uses an `Arc` internally, so `Clone` is cheap.
217+ #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
218+ pub struct TableName ( Arc < str > ) ;
219+
220+ impl From < Arc < str > > for TableName {
221+ fn from ( name : Arc < str > ) -> Self {
222+ TableName ( name)
223+ }
224+ }
225+
226+ impl From < Box < str > > for TableName {
227+ fn from ( name : Box < str > ) -> Self {
228+ TableName ( name. into ( ) )
229+ }
230+ }
231+
232+ impl From < String > for TableName {
233+ fn from ( name : String ) -> Self {
234+ TableName ( name. into ( ) )
235+ }
236+ }
237+
238+ impl std:: ops:: Deref for TableName {
239+ type Target = str ;
240+ fn deref ( & self ) -> & Self :: Target {
241+ & * self . 0
242+ }
243+ }
244+
245+ impl TableName {
246+ pub fn from_str ( name : & str ) -> Self {
247+ TableName ( name. into ( ) )
248+ }
249+ }
250+
251+ impl std:: fmt:: Display for TableName {
252+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
253+ self . 0 . fmt ( f)
254+ }
255+ }
256+
214257/// A subscription defines a view over a table
215258#[ derive( Debug ) ]
216259pub struct SubscriptionPlan {
217260 /// To which table are we subscribed?
218261 return_id : TableId ,
219262 /// To which table are we subscribed?
220- return_name : Arc < str > ,
263+ return_name : TableName ,
221264 /// A subscription can read from multiple tables.
222265 /// From which tables do we read?
223266 table_ids : Vec < TableId > ,
@@ -243,7 +286,7 @@ impl SubscriptionPlan {
243286 }
244287
245288 /// To which table does this plan subscribe?
246- pub fn subscribed_table_name ( & self ) -> & Arc < str > {
289+ pub fn subscribed_table_name ( & self ) -> & TableName {
247290 & self . return_name
248291 }
249292
@@ -333,7 +376,7 @@ impl SubscriptionPlan {
333376
334377 let mut subscriptions = vec ! [ ] ;
335378
336- let return_name = Arc :: < str > :: from ( return_name) ;
379+ let return_name = TableName :: from ( return_name) ;
337380
338381 for plan in plans {
339382 if has_non_index_join ( & plan) {
@@ -346,7 +389,7 @@ impl SubscriptionPlan {
346389
347390 subscriptions. push ( Self {
348391 return_id,
349- return_name : Arc :: clone ( & return_name ) ,
392+ return_name : return_name . clone ( ) ,
350393 table_ids,
351394 plan,
352395 fragments,
0 commit comments