| 833 | } |
| 834 | |
| 835 | pub fn format_string<T>(&self, s: &T) -> Result<String, FormatSpecError> |
| 836 | where |
| 837 | T: CharLen + Deref<Target = str>, |
| 838 | { |
| 839 | self.validate_format(FormatType::String)?; |
| 840 | match self.format_type { |
| 841 | Some(FormatType::String) | None => self |
| 842 | .format_sign_and_align(s, "", FormatAlign::Left) |
| 843 | .map(|mut value| { |
| 844 | if let Some(precision) = self.precision { |
| 845 | value.truncate(precision); |
| 846 | } |
| 847 | value |
| 848 | }), |
| 849 | _ => { |
| 850 | let ch = char::from(self.format_type.as_ref().unwrap()); |
| 851 | Err(FormatSpecError::UnknownFormatCode(ch, "str")) |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | pub fn format_complex(&self, num: &Complex64) -> Result<String, FormatSpecError> { |
| 857 | let (formatted_re, formatted_im) = self.format_complex_re_im(num)?; |