2

I think this might work if I can work out the lifetime notation, am I wrong?

pub fn from<T:Pattern>(from: T) -> Result<Tag, &'static str> { match from { 'A'|"A" => Ok(Tag::ChA), 'B'|"B" => Ok(Tag::ChB), 'C'|"C" => Ok(Tag::ChC), 'D'|"D" => Ok(Tag::ChD), 'T'|"Tmpr" => Ok(Tag::Tmpr), 'Y'|"Batt" => Ok(Tag::Batt), 'L'|"Acc" => Ok(Tag::Acc), _ => Err("Error: unknown channel"), } } 

1 Answer 1

5

Matching only works with concrete types, so the answer is no. Nothing is known about the type T here except that we can call the methods defined in Pattern on it (which are for searching in a string).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.