stylish_core/
arguments.rs

1use crate::{Display, Formatter, Result};
2
3#[doc(hidden)]
4/// pub for macros
5pub struct StdFmt<'a> {
6    #[doc(hidden)]
7    /// pub for macros
8    pub f: &'a (dyn Fn(&mut core::fmt::Formatter<'_>) -> Result + 'a),
9}
10
11impl core::fmt::Display for StdFmt<'_> {
12    #[inline]
13    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result {
14        (self.f)(f)
15    }
16}
17
18impl core::fmt::Debug for StdFmt<'_> {
19    #[inline]
20    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result {
21        (self.f)(f)
22    }
23}
24
25#[doc(hidden)]
26#[allow(missing_debug_implementations)]
27/// pub for macros
28pub struct StdFmtOther<'a>(
29    #[doc(hidden)]
30    /// pub for macros
31    pub StdFmt<'a>,
32);
33
34#[doc(hidden)]
35#[allow(missing_debug_implementations)]
36/// pub for macros
37pub struct StdFmtDebug<'a>(
38    #[doc(hidden)]
39    /// pub for macros
40    pub StdFmt<'a>,
41);
42
43/// A precompiled version of a format string and its by-reference arguments.
44///
45/// Currently this can only be constructed via [`stylish::format_args!`], but it
46/// may be possible to dynamically construct this at runtime in the future.
47///
48/// ```rust
49/// let args = stylish::format_args!("{:(bg=red)} Will Robinson", "Danger");
50/// assert_eq!(
51///     stylish::html::format!("{:s}", args),
52///     "<span style=background-color:red>Danger</span> Will Robinson",
53/// );
54/// ```
55#[allow(missing_debug_implementations)]
56pub struct Arguments<'a> {
57    #[doc(hidden)]
58    /// pub for macros
59    pub f: &'a (dyn Fn(&mut Formatter<'_>) -> Result + 'a),
60}
61
62impl Display for StdFmtOther<'_> {
63    #[inline]
64    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
65        let arg = &self.0;
66        std_write!(f, Other, arg)
67    }
68}
69
70impl Display for StdFmtDebug<'_> {
71    #[inline]
72    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
73        let arg = &self.0;
74        std_write!(f, Debug, arg)
75    }
76}
77
78impl Display for Arguments<'_> {
79    #[inline]
80    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
81        (self.f)(f)
82    }
83}