Lines Matching defs:format
2896 assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
2899 assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]");
4666 format!("{:?}", c),
6086 assert_eq!(format!("{:?}", x), "[]");
6087 assert_eq!(format!("{:?}", vec![1]), "[1]");
6088 assert_eq!(format!("{:?}", vec![1, 2, 3]), "[1, 2, 3]");
6089 assert!(format!("{:?}", vec![vec![], vec![1], vec![1, 1]]) == "[[], [1], [1, 1]]");
6467 let s: String = format!("{}{}", a, b);
6625 assert_eq!("[]", format!("{:?}", vec1));
6628 assert_eq!("[0, 1]", format!("{:?}", vec2));
6631 assert_eq!("[4, 5]", format!("{:?}", slice));
7449 let debug = format!("{:?}", into_iter);
10372 assert_eq!(format!("{:?}", x), x_str);
10373 assert_eq!(format!("{:?}", x), x_str);
11853 assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
11856 assert_eq!(format!("{:?}", ringbuf), "[\"just\", \"one\", \"test\", \"more\"]");
12967 let s = fmt::format(format_args!("Hello, {}!", "world"));
13008 t!(format!(""), "");
13009 t!(format!("hello"), "hello");
13010 t!(format!("hello {{"), "hello {");
13013 t!(format!("{}", 1.0f32), "1");
13014 t!(format!("{}", 1.0f64), "1");
13015 t!(format!("{}", "a"), "a");
13016 t!(format!("{}", "a".to_string()), "a");
13017 t!(format!("{}", false), "false");
13018 t!(format!("{}", 'a'), "a");
13021 t!(format!("{}", true), "true");
13022 t!(format!("{}", '☃'), "☃");
13023 t!(format!("{}", 10), "10");
13024 t!(format!("{}", 10_usize), "10");
13025 t!(format!("{:?}", '☃'), "'☃'");
13026 t!(format!("{:?}", 10), "10");
13027 t!(format!("{:?}", 10_usize), "10");
13028 t!(format!("{:?}", "true"), "\"true\"");
13029 t!(format!("{:?}", "foo\nbar"), "\"foo\\nbar\"");
13030 t!(format!("{:?}", "foo\n\"bar\"\r\n\'baz\'\t\\qux\\"), r#""foo\n\"bar\"\r\n'baz'\t\\qux\\""#);
13031 t!(format!("{:?}", "foo\0bar\x01baz\u{7f}q\u{75}x"), r#""foo\u{0}bar\u{1}baz\u{7f}qux""#);
13032 t!(format!("{:o}", 10_usize), "12");
13033 t!(format!("{:x}", 10_usize), "a");
13034 t!(format!("{:X}", 10_usize), "A");
13035 t!(format!("{}", "foo"), "foo");
13036 t!(format!("{}", "foo".to_string()), "foo");
13038 t!(format!("{:#p}", 0x1234 as *const isize), "0x00001234");
13039 t!(format!("{:#p}", 0x1234 as *mut isize), "0x00001234");
13041 t!(format!("{:#p}", 0x1234 as *const isize), "0x0000000000001234");
13042 t!(format!("{:#p}", 0x1234 as *mut isize), "0x0000000000001234");
13044 t!(format!("{:p}", 0x1234 as *const isize), "0x1234");
13045 t!(format!("{:p}", 0x1234 as *mut isize), "0x1234");
13046 t!(format!("{:x}", A), "aloha");
13047 t!(format!("{:X}", B), "adios");
13048 t!(format!("foo {} ☃☃☃☃☃☃", "bar"), "foo bar ☃☃☃☃☃☃");
13049 t!(format!("{1} {0}", 0, 1), "1 0");
13050 t!(format!("{foo} {bar}", foo = 0, bar = 1), "0 1");
13051 t!(format!("{foo} {1} {bar} {0}", 0, 1, foo = 2, bar = 3), "2 1 3 0");
13052 t!(format!("{} {0}", "a"), "a a");
13053 t!(format!("{_foo}", _foo = 6usize), "6");
13054 t!(format!("{foo_bar}", foo_bar = 1), "1");
13055 t!(format!("{}", 5 + 5), "10");
13056 t!(format!("{:#4}", C), "☃123");
13057 t!(format!("{:b}", D), "aa☃bb");
13060 t!(format!("{:?}", a), "1");
13063 t!(format!("{}", "a"), "a");
13064 t!(format!("{:4}", "a"), "a ");
13065 t!(format!("{:4}", "☃"), "☃ ");
13066 t!(format!("{:>4}", "a"), " a");
13067 t!(format!("{:<4}", "a"), "a ");
13068 t!(format!("{:^5}", "a"), " a ");
13069 t!(format!("{:^5}", "aa"), " aa ");
13070 t!(format!("{:^4}", "a"), " a ");
13071 t!(format!("{:^4}", "aa"), " aa ");
13072 t!(format!("{:.4}", "a"), "a");
13073 t!(format!("{:4.4}", "a"), "a ");
13074 t!(format!("{:4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
13075 t!(format!("{:<4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
13076 t!(format!("{:>4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
13077 t!(format!("{:^4.4}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
13078 t!(format!("{:>10.4}", "aaaaaaaaaaaaaaaaaa"), " aaaa");
13079 t!(format!("{:2.4}", "aaaaa"), "aaaa");
13080 t!(format!("{:2.4}", "aaaa"), "aaaa");
13081 t!(format!("{:2.4}", "aaa"), "aaa");
13082 t!(format!("{:2.4}", "aa"), "aa");
13083 t!(format!("{:2.4}", "a"), "a ");
13084 t!(format!("{:0>2}", "a"), "0a");
13085 t!(format!("{:.*}", 4, "aaaaaaaaaaaaaaaaaa"), "aaaa");
13086 t!(format!("{:.1$}", "aaaaaaaaaaaaaaaaaa", 4), "aaaa");
13087 t!(format!("{:.a$}", "aaaaaaaaaaaaaaaaaa", a = 4), "aaaa");
13088 t!(format!("{:._a$}", "aaaaaaaaaaaaaaaaaa", _a = 4), "aaaa");
13089 t!(format!("{:1$}", "a", 4), "a ");
13090 t!(format!("{1:0$}", 4, "a"), "a ");
13091 t!(format!("{:a$}", "a", a = 4), "a ");
13092 t!(format!("{:-#}", "a"), "a");
13093 t!(format!("{:+#}", "a"), "a");
13094 t!(format!("{:/^10.8}", "1234567890"), "/12345678/");
13097 t!(format!("{:}", 1.0f32), "1");
13098 t!(format!("{:}", 1.0f64), "1");
13099 t!(format!("{:.3}", 1.0f64), "1.000");
13100 t!(format!("{:10.3}", 1.0f64), " 1.000");
13101 t!(format!("{:+10.3}", 1.0f64), " +1.000");
13102 t!(format!("{:+10.3}", -1.0f64), " -1.000");
13104 t!(format!("{:e}", 1.2345e6f32), "1.2345e6");
13105 t!(format!("{:e}", 1.2345e6f64), "1.2345e6");
13106 t!(format!("{:E}", 1.2345e6f64), "1.2345E6");
13107 t!(format!("{:.3e}", 1.2345e6f64), "1.234e6");
13108 t!(format!("{:10.3e}", 1.2345e6f64), " 1.234e6");
13109 t!(format!("{:+10.3e}", 1.2345e6f64), " +1.234e6");
13110 t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6");
13113 t!(format!("{}", -0.0), "-0");
13114 t!(format!("{:?}", 0.0), "0.0");
13117 t!(format!("{:<3}", 1), "1 ");
13118 t!(format!("{:>3}", 1), " 1");
13119 t!(format!("{:^3}", 1), " 1 ");
13120 t!(format!("{:03}", 1), "001");
13121 t!(format!("{:<03}", 1), "001");
13122 t!(format!("{:>03}", 1), "001");
13123 t!(format!("{:^03}", 1), "001");
13124 t!(format!("{:+03}", 1), "+01");
13125 t!(format!("{:<+03}", 1), "+01");
13126 t!(format!("{:>+03}", 1), "+01");
13127 t!(format!("{:^+03}", 1), "+01");
13128 t!(format!("{:#05x}", 1), "0x001");
13129 t!(format!("{:<#05x}", 1), "0x001");
13130 t!(format!("{:>#05x}", 1), "0x001");
13131 t!(format!("{:^#05x}", 1), "0x001");
13132 t!(format!("{:05}", 1.2), "001.2");
13133 t!(format!("{:<05}", 1.2), "001.2");
13134 t!(format!("{:>05}", 1.2), "001.2");
13135 t!(format!("{:^05}", 1.2), "001.2");
13136 t!(format!("{:05}", -1.2), "-01.2");
13137 t!(format!("{:<05}", -1.2), "-01.2");
13138 t!(format!("{:>05}", -1.2), "-01.2");
13139 t!(format!("{:^05}", -1.2), "-01.2");
13140 t!(format!("{:+05}", 1.2), "+01.2");
13141 t!(format!("{:<+05}", 1.2), "+01.2");
13142 t!(format!("{:>+05}", 1.2), "+01.2");
13143 t!(format!("{:^+05}", 1.2), "+01.2");
13146 t!(format!("{0:x} {0:X}", 15), "f F");
13147 t!(format!("{0:x} {0:X} {}", 15), "f F 15");
13148 t!(format!("{:x}{0:X}{a:x}{:X}{1:x}{a:X}", 13, 14, a = 15), "dDfEeF");
13149 t!(format!("{a:x} {a:X}", a = 15), "f F");
13153 format!(
13162 t!(format!("{a:.*} {0} {:.*}", 4, 3, "efgh", a = "abcdef"), "abcd 4 efg");
13163 t!(format!("{:.a$} {a} {a:#x}", "aaaaaa", a = 2), "aa 2 0x2");
13168 let exp = format!("{:#x}", val);
13169 t!(format!("{:p}", val as *const isize), exp);
13173 t!(format!("{{"), "{");
13174 t!(format!("}}"), "}");
13176 // make sure that format! doesn't move out of local variables
13178 format!("{}", a);
13179 format!("{}", a);
13181 // make sure that format! doesn't cause spurious unused-unsafe warnings when
13185 format!("{}", a);
13189 format!("{}", "test",);
13190 format!("{foo}", foo = "test",);
13237 let s = fmt::format(format_args!("hello {}", "world"));
13239 let s = format!("{}: {}", "args were", format_args!("hello {}", "world"));
13245 // Make sure format!() arguments are always evaluated in a left-to-right
13255 format!("{} {} {a} {b} {} {c}", foo(), foo(), foo(), a = foo(), b = foo(), c = foo()),
13271 assert_eq!(format!("{0} {0} {0} {a} {a} {a}", foo(), a = foo()), "1 1 1 2 2 2".to_string());
13277 assert_eq!(format!("{:?}", refcell), "RefCell { value: 5 }");
13279 assert_eq!(format!("{:?}", refcell), "RefCell { value: <borrowed> }");
13281 assert_eq!(format!("{:?}", refcell), "RefCell { value: 5 }");
13949 /// The first argument `format!` receives is a format string. This must be a string
13952 /// Additional parameters passed to `format!` replace the `{}`s within the
13956 /// A common use for `format!` is concatenation and interpolation of strings.
13971 /// `format!` panics if a formatting trait implementation returns an error.
13978 /// format!("test");
13979 /// format!("hello {}", "world!");
13980 /// format!("x = {}, y = {y}", 10, y = 30);
13985 macro_rules! format {
13987 let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
15889 assert_eq!(format!("{:?}", a), "5");
15901 assert_eq!(format!("{:?}", x), "[1, 2, 3]");
15913 assert_eq!(format!("{:?}", x), "\"swordfish\"");
16063 assert_eq!(format!("{:?}", r), "()");
25803 //! This module contains the runtime support for the [`format!`] syntax extension.
25805 //! order to format arguments at runtime into strings.
25809 //! The [`format!`] macro is intended to be familiar to those coming from C's
25810 //! `printf`/`fprintf` functions or Python's `str.format` function.
25812 //! Some examples of the [`format!`] extension are:
25815 //! format!("Hello"); // => "Hello"
25816 //! format!("Hello, {}!", "world"); // => "Hello, world!"
25817 //! format!("The number is {}", 1); // => "The number is 1"
25818 //! format!("{:?}", (3, 4)); // => "(3, 4)"
25819 //! format!("{value}", value=4); // => "4"
25820 //! format!("{} {}", 1, 2); // => "1 2"
25821 //! format!("{:04}", 42); // => "0042" with leading zeros
25822 //! format!("{:#?}", (100, 200)); // => "(
25828 //! From these, you can see that the first argument is a format string. It is
25831 //! will then parse the format string and determine if the list of arguments
25832 //! provided is suitable to pass to this format string.
25841 //! example, the format string `{} {} {}` would take three parameters, and they
25842 //! would be formatted in the same order as they're given. The format string
25843 //! `{2} {1} {0}`, however, would format arguments in reverse order.
25851 //! format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2"
25860 //! A format string is required to use all of its arguments, otherwise it is a
25862 //! format string.
25867 //! function, but the [`format!`] macro is a syntax extension that allows it to
25875 //! For example, the following [`format!`] expressions all use named argument:
25878 //! format!("{argument}", argument = "test"); // => "test"
25879 //! format!("{name} {}", 1, name = 2); // => "2 1"
25880 //! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
25885 //! valid to provide named parameters that are unused by the format string.
25903 //! This is a parameter for the "minimum width" that the format should take up.
25919 //! assert_eq!(format!("Hello {:<5}!", "x"), "Hello x !");
25920 //! assert_eq!(format!("Hello {:-<5}!", "x"), "Hello x----!");
25921 //! assert_eq!(format!("Hello {:^5}!", "x"), "Hello x !");
25922 //! assert_eq!(format!("Hello {:>5}!", "x"), "Hello x!");
25943 //! padding is applied is to format your input, then pad this resulting string
25947 //! println!("Hello {:^15}!", format!("{:?}", Some("hi"))); // => "Hello Some("hi") !"
25953 //! assert_eq!(format!("Hello {:+}!", 5), "Hello +5!");
25954 //! assert_eq!(format!("{:#x}!", 27), "0x1b!");
25955 //! assert_eq!(format!("Hello {:05}!", 5), "Hello 00005!");
25956 //! assert_eq!(format!("Hello {:05}!", -5), "Hello -0005!");
25957 //! assert_eq!(format!("{:#010x}!", 27), "0x0000001b!");
25975 //! both be done with a `0` character as well as be sign-aware. A format
25977 //! same format would yield `-0000001` for the integer `-1`. Notice that
26003 //! use format *argument* `N` (which must be a `usize`) as the precision.
26007 //! `.*` means that this `{...}` is associated with *two* format inputs rather than one: the
26009 //! in this case, if one uses the format string `{<arg>:<spec>.*}`, then the `<arg>` part refers
26056 //! depends on the operating system's locale setting. The format functions
26075 //! assert_eq!(format!("Hello {{}}"), "Hello {}");
26076 //! assert_eq!(format!("{{ Hello"), "{ Hello");
26081 //! To summarize, here you can find the full grammar of format strings.
26089 //! maybe_format := '{' '{' | '}' '}' | format
26090 //! format := '{' [ argument ] [ ':' format_spec ] '}'
26127 //! standard library as well. If no format is specified (as in `{}` or `{:6}`),
26128 //! then the format trait used is the [`Display`] trait.
26130 //! When implementing a format trait for your own type, you will have to
26144 //! should emit output into the `f.buf` stream. It is up to each format trait
26177 //! // various flags provided to format strings.
26183 //! // of this format is to print the magnitude of a vector.
26194 //! let string = format!("{:.*}", decimals, magnitude);
26223 //! assert_eq!(format!("{} {:?}", 3, 4), "3 4");
26224 //! assert_eq!(format!("{} {:?}", 'a', 'b'), "a 'b'");
26225 //! assert_eq!(format!("{} {:?}", "foo\n", "bar\n"), "foo\n \"bar\\n\"");
26230 //! There are a number of related macros in the [`format!`] family. The ones that
26234 //! format! // described above
26237 //! print! // the format string is printed to the standard output
26239 //! eprint! // the format string is printed to the standard error
26246 //! This and [`writeln!`] are two macros which are used to emit the format string
26248 //! format strings and instead directly write the output. Under the hood, this
26278 //! an opaque object describing the format string. This object
26299 //! This structure can then be passed to the [`write`] and [`format`] functions
26300 //! inside this module in order to process the format string.
26313 //! [`format!`]: crate::format
26324 //! [`format`]: crate::format
26351 /// The `format` function takes an [`Arguments`] struct and returns the resulting
26363 /// let s = fmt::format(format_args!("Hello, {}!", "world"));
26367 /// Please note that using [`format!`] might be preferable.
26371 /// let s = format!("Hello, {}!", "world");
26376 /// [`format!`]: crate::format
26378 pub fn format(args: Arguments<'_>) -> string::String {
26695 assert_eq!(format!("{:?}", foo), "75");
26710 assert_eq!(format!("{:?}", x), "\"swordfish\"");
26837 assert_eq!(format!("{:?}", r), "()");
34727 let set_str = format!("{:?}", set);
34730 assert_eq!(format!("{:?}", empty), "{}");
34914 format!("{:?}", set);
34915 format!("{:?}", set.iter());
34916 format!("{:?}", set.into_iter());
37326 format!("{:?}", map);
37327 format!("{:?}", map.iter());
37328 format!("{:?}", map.iter_mut());
37329 format!("{:?}", map.keys());
37330 format!("{:?}", map.values());
37331 format!("{:?}", map.values_mut());
37333 format!("{:?}", map.into_iter());
37335 format!("{:?}", map.into_keys());
37337 format!("{:?}", map.into_values());
39660 result += &format!("\n{}{:?}", indent, leaf.keys());
39666 result += &format!("\n{}{:?}", indent, kv.into_kv().0);
51994 let a_str = format!("{:?}", a);
51995 let b_str = format!("{:?}", b);
52003 let s = format!("{:?}", a);
52005 let s = format!("{:?}", b);