Skip to content
Myr

token.rs

This file

Path

src/exec/token.rs

37 lines · 1.2 KiB · Rust

Last changed by

Not known.

History of this file

Take it

1// Copyright (c) 2017 fd developers2// Licensed under the Apache License, Version 2.03// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>4// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.89use std::fmt::{self, Display, Formatter};1011/// Designates what should be written to a buffer12///13/// Each `Token` contains either text, or a placeholder variant, which will be used to generate14/// commands after all tokens for a given command template have been collected.15#[derive(Clone, Debug, PartialEq)]16pub enum Token {17    Placeholder,18    Basename,19    Parent,20    NoExt,21    BasenameNoExt,22    Text(String),23}2425impl Display for Token {26    fn fmt(&self, f: &mut Formatter) -> fmt::Result {27        match *self {28            Token::Placeholder => f.write_str("{}")?,29            Token::Basename => f.write_str("{/}")?,30            Token::Parent => f.write_str("{//}")?,31            Token::NoExt => f.write_str("{.}")?,32            Token::BasenameNoExt => f.write_str("{/.}")?,33            Token::Text(ref string) => f.write_str(string)?,34        }35        Ok(())36    }37}