mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-01 09:20:29 +08:00
trailers: add Token constructor
During the reorganisation of the codebase, the constructors for Token were removed. Add back a constructor via the `TryFrom<&'a str>` trait. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -130,6 +130,19 @@ impl Deref for Token<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for Token<'a> {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
|
||||
let is_token = s.chars().all(|c| c.is_alphanumeric() || c == '-');
|
||||
if is_token {
|
||||
Ok(Token(s))
|
||||
} else {
|
||||
Err("token contains invalid characters")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Display<'a> {
|
||||
trailer: &'a Trailer<'a>,
|
||||
separator: &'a str,
|
||||
|
||||
Reference in New Issue
Block a user