I have a type:
#[derive(Clone, Debug)]
pub enum Value {
...
Int(i64),
List(List),
Map(Map),
Real(f64),
Str(String),
}
And some From
functions, e.g.,
impl From<f32> for Value {
fn from(f: f32) -> Self {
Value::Real(f as f64)
}
}
impl From<f64> for Value {
fn from(f: f64) -> Self {
Value::Real(f)
}
}
impl From<&str> for Value {
fn from(s: &str) -> Self {
Value::Str(s.to_string())
}
}
...
And this function:
impl Value {
pub fn push(&mut self, value: Value) -> Result<()> {
...
So, given mut v
of type Value::List
, I can write: v.push(200.into())
and v.push("more".into())
.
What I'd like to be able to do is #1: v.push(200)
and v.push("more")
; and #2 v.push_many(&[200, 100, 75])
and v.push_many(&["more", "some"])
.
I could imagine I'd need a signature something like: fn push<T>(&mut self, values: &[T]) -> Result<()>
, but how would I specify that T
had to be of type Value
?