TryFrom<&str> to FromStr for SymbolPair

This commit is contained in:
Giulio De Pasquale 2021-01-22 16:08:03 +00:00
parent 2216910edb
commit 85c02e4053

View File

@ -6,6 +6,7 @@ use std::fmt::{Display, Formatter};
use regex::Regex;
use crate::BoxError;
use std::str::FromStr;
#[derive(Clone, PartialEq, Hash, Debug, Eq)]
pub struct Symbol {
@ -85,10 +86,10 @@ impl Into<String> for SymbolPair {
}
}
impl TryFrom<&str> for SymbolPair {
type Error = BoxError;
impl FromStr for SymbolPair {
type Err = BoxError;
fn try_from(value: &str) -> Result<Self, Self::Error> {
fn from_str(value: &str) -> Result<Self, Self::Err> {
const REGEX: &str = r"^[t|f](?P<base>\w{3,7}):?(?P<quote>\w{3,7})";
let captures = Regex::new(REGEX)?.captures(&value).ok_or("Invalid input")?;