Skip to main content

clap_config_fallback/
format.rs

1use std::{ffi::OsString, path::PathBuf};
2
3pub fn path(value: PathBuf) -> String {
4    value.display().to_string()
5}
6
7pub trait FormatArg<T> {
8    fn format(&self, value: T) -> OsString;
9}
10
11#[derive(Debug, Clone, Copy, Default)]
12pub struct DefaultFormat;
13
14impl<T> FormatArg<T> for DefaultFormat
15where
16    T: ToString,
17{
18    fn format(&self, value: T) -> OsString {
19        value.to_string().into()
20    }
21}
22
23pub struct CustomFormat<F>(pub F);
24
25impl<T, F, R> FormatArg<T> for CustomFormat<F>
26where
27    F: Fn(T) -> R,
28    R: ToString,
29{
30    fn format(&self, value: T) -> OsString {
31        (self.0)(value).to_string().into()
32    }
33}