// Copyright (c) 2017 fd developers // Licensed under the Apache License, Version 2.0 // // or the MIT license , // at your option. All files in the project carrying such // notice may not be copied, modified, or distributed except // according to those terms. use std::fmt::{self, Display, Formatter}; /// Designates what should be written to a buffer /// /// Each `Token` contains either text, or a placeholder variant, which will be used to generate /// commands after all tokens for a given command template have been collected. #[derive(Clone, Debug, PartialEq)] pub enum Token { Placeholder, Basename, Parent, NoExt, BasenameNoExt, Text(String), } impl Display for Token { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match *self { Token::Placeholder => f.write_str("{}")?, Token::Basename => f.write_str("{/}")?, Token::Parent => f.write_str("{//}")?, Token::NoExt => f.write_str("{.}")?, Token::BasenameNoExt => f.write_str("{/.}")?, Token::Text(ref string) => f.write_str(string)?, } Ok(()) } }