graphql-rust / graphql-parser

A graphql query language and schema definition language parser and formatter for rust
Apache License 2.0
351 stars 74 forks source link

Requiring Text to be Clone #72

Open yrashk opened 1 year ago

yrashk commented 1 year ago

I have a case where to clone structures like Field, I need to have an additional constraint for T to be Clone, which quickly proliferates through the codebase when T is kept generic.

Is there any specific reason for the Text trait not requiring Clone from the get-go? For the implementations defined in the project, it works just fine:

diff --git a/src/common.rs b/src/common.rs
index c5189fa..f44b5b2 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -11,7 +11,7 @@ use crate::position::Pos;

 /// Text abstracts over types that hold a string value.
 /// It is used to make the AST generic over the string type.
-pub trait Text<'a>: 'a {
+pub trait Text<'a>: 'a + Clone {
     type Value: 'a + From<&'a str> + AsRef<str> + std::borrow::Borrow<str> + PartialEq + Eq + PartialOrd + Ord + fmt::Debug + Clone; 
 }

Is there an anticipation that somebody will use an implementation of Text that is not cloneable?