1 //! An "interner" is a data structure that associates values with usize tags and
2 //! allows bidirectional lookup; i.e., given a value, one can easily find the
3 //! type, and vice versa.
5 use arena::DroplessArena;
6 use rustc_data_structures::fx::FxHashMap;
7 use rustc_data_structures::indexed_vec::Idx;
8 use rustc_data_structures::newtype_index;
9 use rustc_macros::symbols;
10 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
11 use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable};
13 use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
15 use std::hash::{Hash, Hasher};
18 use crate::{Span, DUMMY_SP, GLOBALS};
24 // After modifying this list adjust `is_special`, `is_used_keyword`/`is_unused_keyword`,
25 // this should be rarely necessary though if the keywords are kept in alphabetic order.
27 // Special reserved identifiers used internally for elided lifetimes,
28 // unnamed method parameters, crate root module, error recovery etc.
31 DollarCrate: "$crate",
34 // Keywords that are used in stable Rust.
71 // Keywords that are used in unstable Rust or reserved for future use.
85 // Edition-specific keywords that are used in stable Rust.
86 Async: "async", // >= 2018 Edition only
87 Await: "await", // >= 2018 Edition only
88 Dyn: "dyn", // >= 2018 Edition only
90 // Edition-specific keywords that are used in unstable Rust or reserved for future use.
91 Try: "try", // >= 2018 Edition only
93 // Special lifetime names
94 UnderscoreLifetime: "'_",
95 StaticLifetime: "'static",
97 // Weak keywords, have special meaning only in specific contexts.
104 // Symbols that can be referred to with syntax_pos::sym::*. The symbol is
105 // the stringified identifier unless otherwise specified (e.g.
106 // `proc_dash_macro` represents "proc-macro").
108 // As well as the symbols listed, there are symbols for the the strings
109 // "0", "1", ..., "9", which are accessible via `sym::integer`.
111 aarch64_target_feature,
114 abi_msp430_interrupt,
122 advanced_slice_patterns,
134 allow_internal_unsafe,
135 allow_internal_unstable,
136 allow_internal_unstable_backcompat_hack,
140 arbitrary_enum_discriminant,
141 arbitrary_self_types,
148 associated_type_bounds,
149 associated_type_defaults,
156 augmented_assignments,
157 automatically_derived,
158 avx512_target_feature,
163 bind_by_move_pattern_guards,
166 borrowck_graphviz_postflow,
167 borrowck_graphviz_preflow,
170 braced_empty_structs,
178 cfg_target_has_atomic,
179 cfg_target_thread_local,
187 closure_to_fn_coercion,
189 cmpxchg16b_target_feature,
196 conservative_impl_trait,
198 const_compare_raw_pointers,
204 const_in_array_repeat_expressions,
208 const_raw_ptr_to_usize_cast,
222 crate_visibility_modifier,
225 custom_inner_attributes,
226 custom_test_frameworks,
234 default_lib_allocator,
235 default_type_parameter_fallback,
251 document_private_items,
252 dotdoteq_in_patterns,
253 dotdot_in_tuple_patterns,
254 double_braced_crate: "{{crate}}",
255 double_braced_impl: "{{impl}}",
256 double_braced_misc: "{{misc}}",
257 double_braced_closure: "{{closure}}",
258 double_braced_constructor: "{{constructor}}",
259 double_braced_constant: "{{constant}}",
260 double_braced_opaque: "{{opaque}}",
262 dropck_parametricity,
277 exclusive_range_pattern,
278 exhaustive_integer_patterns,
284 extern_absolute_paths,
286 extern_crate_item_prelude,
297 field_init_shorthand,
320 generic_associated_types,
329 hexagon_target_feature,
331 homogeneous_aggregate,
345 if_while_or_patterns,
347 impl_header_lifetime_elision,
349 impl_trait_in_bindings,
357 inclusive_range_syntax,
358 infer_outlives_requirements,
359 infer_static_outlives_requirements,
366 irrefutable_let_patterns,
369 issue_5723_bootstrap,
370 issue_tracker_base_url,
390 link_llvm_intrinsics,
399 macro_at_most_once_rep,
402 macro_lifetime_matcher,
403 macro_literal_matcher,
414 match_beginning_vert,
415 match_default_bindings,
428 movbe_target_feature,
462 omit_gdb_pretty_printer_section,
469 optin_builtin_traits,
479 overlapping_marker_traits,
484 panic_implementation,
504 poll_with_tls_context,
505 powerpc_target_feature,
506 precise_pointer_size_matching,
510 proc_dash_macro: "proc-macro",
512 proc_macro_attribute,
518 proc_macro_internals,
520 proc_macro_non_items,
521 proc_macro_path_invoc,
525 quad_precision_float,
538 reexport_test_harness_main,
548 re_rebalance_coherence,
564 rustc_allocator_nounwind,
565 rustc_allow_const_fn_ptr,
566 rustc_args_required_const,
570 rustc_const_unstable,
571 rustc_conversion_suggestion,
574 rustc_diagnostic_item,
575 rustc_diagnostic_macros,
578 rustc_dump_env_program_clauses,
579 rustc_dump_program_clauses,
580 rustc_dump_user_substs,
582 rustc_expected_cgu_reuse,
583 rustc_if_this_changed,
584 rustc_inherit_overflow_checks,
586 rustc_layout_scalar_valid_range_end,
587 rustc_layout_scalar_valid_range_start,
588 rustc_macro_transparency,
590 rustc_nonnull_optimization_guaranteed,
591 rustc_object_lifetime_default,
592 rustc_on_unimplemented,
595 rustc_partition_codegened,
596 rustc_partition_reused,
598 rustc_peek_definite_init,
599 rustc_peek_maybe_init,
600 rustc_peek_maybe_uninit,
602 rustc_proc_macro_decls,
606 rustc_std_internal_symbol,
609 rustc_reservation_impl,
611 rustc_then_this_would_need,
616 rust_eh_unwind_resume,
618 rvalue_static_promotion,
635 sse4a_target_feature,
648 stmt_expr_attributes,
650 struct_field_attributes,
662 termination_trait_test,
665 test_accepted_feature,
667 test_removed_feature,
687 type_alias_impl_trait,
690 type_alias_enum_variants,
700 underscore_const_names,
702 underscore_lifetimes,
705 universal_impl_trait,
708 unrestricted_attribute_tokens,
711 unsized_tuple_coercion,
726 visible_private_types,
729 warn_directory_ownership,
740 #[derive(Copy, Clone, Eq)]
748 /// Constructs a new identifier from a symbol and a span.
749 pub const fn new(name: Symbol, span: Span) -> Ident {
753 /// Constructs a new identifier with a dummy span.
755 pub const fn with_dummy_span(name: Symbol) -> Ident {
756 Ident::new(name, DUMMY_SP)
760 pub fn invalid() -> Ident {
761 Ident::with_dummy_span(kw::Invalid)
764 /// Maps an interned string to an identifier with an empty syntax context.
765 pub fn from_interned_str(string: InternedString) -> Ident {
766 Ident::with_dummy_span(string.as_symbol())
769 /// Maps a string to an identifier with a dummy span.
770 pub fn from_str(string: &str) -> Ident {
771 Ident::with_dummy_span(Symbol::intern(string))
774 /// Maps a string and a span to an identifier.
775 pub fn from_str_and_span(string: &str, span: Span) -> Ident {
776 Ident::new(Symbol::intern(string), span)
779 /// Replaces `lo` and `hi` with those from `span`, but keep hygiene context.
780 pub fn with_span_pos(self, span: Span) -> Ident {
781 Ident::new(self.name, span.with_ctxt(self.span.ctxt()))
784 pub fn without_first_quote(self) -> Ident {
785 Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
788 /// "Normalize" ident for use in comparisons using "item hygiene".
789 /// Identifiers with same string value become same if they came from the same "modern" macro
790 /// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
791 /// different "modern" macros.
792 /// Technically, this operation strips all non-opaque marks from ident's syntactic context.
793 pub fn modern(self) -> Ident {
794 Ident::new(self.name, self.span.modern())
797 /// "Normalize" ident for use in comparisons using "local variable hygiene".
798 /// Identifiers with same string value become same if they came from the same non-transparent
799 /// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
800 /// non-transparent macros.
801 /// Technically, this operation strips all transparent marks from ident's syntactic context.
802 pub fn modern_and_legacy(self) -> Ident {
803 Ident::new(self.name, self.span.modern_and_legacy())
806 /// Transforms an underscore identifier into one with the same name, but
807 /// gensymed. Leaves non-underscore identifiers unchanged.
808 pub fn gensym_if_underscore(self) -> Ident {
809 if self.name == kw::Underscore {
810 let name = with_interner(|interner| interner.gensymed(self.name));
811 Ident::new(name, self.span)
817 /// Convert the name to a `LocalInternedString`. This is a slowish
818 /// operation because it requires locking the symbol interner.
819 pub fn as_str(self) -> LocalInternedString {
823 /// Convert the name to an `InternedString`. This is a slowish operation
824 /// because it requires locking the symbol interner.
825 pub fn as_interned_str(self) -> InternedString {
826 self.name.as_interned_str()
830 impl PartialEq for Ident {
831 fn eq(&self, rhs: &Self) -> bool {
832 self.name == rhs.name && self.span.ctxt() == rhs.span.ctxt()
836 impl Hash for Ident {
837 fn hash<H: Hasher>(&self, state: &mut H) {
838 self.name.hash(state);
839 self.span.ctxt().hash(state);
843 impl fmt::Debug for Ident {
844 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
845 write!(f, "{}{:?}", self.name, self.span.ctxt())
849 impl fmt::Display for Ident {
850 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
851 fmt::Display::fmt(&self.name, f)
855 impl UseSpecializedEncodable for Ident {
856 fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
857 s.emit_struct("Ident", 2, |s| {
858 s.emit_struct_field("name", 0, |s| {
861 s.emit_struct_field("span", 1, |s| {
868 impl UseSpecializedDecodable for Ident {
869 fn default_decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
870 d.read_struct("Ident", 2, |d| {
872 name: d.read_struct_field("name", 0, Decodable::decode)?,
873 span: d.read_struct_field("span", 1, Decodable::decode)?,
879 /// A symbol is an interned or gensymed string. A gensym is a symbol that is
880 /// never equal to any other symbol.
882 /// Conceptually, a gensym can be thought of as a normal symbol with an
883 /// invisible unique suffix. Gensyms are useful when creating new identifiers
884 /// that must not match any existing identifiers, e.g. during macro expansion
885 /// and syntax desugaring. Because gensyms should always be identifiers, all
886 /// gensym operations are on `Ident` rather than `Symbol`. (Indeed, in the
887 /// future the gensym-ness may be moved from `Symbol` to hygiene data.)
891 /// assert_eq!(Ident::from_str("_"), Ident::from_str("_"))
892 /// assert_ne!(Ident::from_str("_").gensym_if_underscore(), Ident::from_str("_"))
894 /// Ident::from_str("_").gensym_if_underscore(),
895 /// Ident::from_str("_").gensym_if_underscore(),
898 /// Internally, a symbol is implemented as an index, and all operations
899 /// (including hashing, equality, and ordering) operate on that index. The use
900 /// of `newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
901 /// because `newtype_index!` reserves the last 256 values for tagging purposes.
903 /// Note that `Symbol` cannot directly be a `newtype_index!` because it
904 /// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
905 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
906 pub struct Symbol(SymbolIndex);
909 pub struct SymbolIndex { .. }
913 const fn new(n: u32) -> Self {
914 Symbol(SymbolIndex::from_u32_const(n))
917 /// Maps a string to its interned representation.
918 pub fn intern(string: &str) -> Self {
919 with_interner(|interner| interner.intern(string))
922 /// Access the symbol's chars. This is a slowish operation because it
923 /// requires locking the symbol interner.
924 pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
925 with_interner(|interner| {
926 f(interner.get(self))
930 /// Access two symbols' chars. This is a slowish operation because it
931 /// requires locking the symbol interner, but it is faster than calling
933 fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: Symbol, f: F) -> R {
934 with_interner(|interner| {
935 f(interner.get(self), interner.get(other))
939 /// Convert to a `LocalInternedString`. This is a slowish operation because
940 /// it requires locking the symbol interner.
941 pub fn as_str(self) -> LocalInternedString {
942 with_interner(|interner| unsafe {
943 LocalInternedString {
944 string: std::mem::transmute::<&str, &str>(interner.get(self))
949 /// Convert to an `InternedString`. This is a slowish operation because it
950 /// requires locking the symbol interner.
951 pub fn as_interned_str(self) -> InternedString {
952 with_interner(|interner| InternedString {
953 symbol: interner.interned(self)
957 pub fn as_u32(self) -> u32 {
962 impl fmt::Debug for Symbol {
963 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
964 let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));
966 write!(f, "{}({:?})", self, self.0)
968 write!(f, "{}", self)
973 impl fmt::Display for Symbol {
974 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
975 fmt::Display::fmt(&self.as_str(), f)
979 impl Encodable for Symbol {
980 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
981 s.emit_str(&self.as_str())
985 impl Decodable for Symbol {
986 fn decode<D: Decoder>(d: &mut D) -> Result<Symbol, D::Error> {
987 Ok(Symbol::intern(&d.read_str()?))
991 // The `&'static str`s in this type actually point into the arena.
993 // Note that normal symbols are indexed upward from 0, and gensyms are indexed
994 // downward from SymbolIndex::MAX_AS_U32.
996 pub struct Interner {
997 arena: DroplessArena,
998 names: FxHashMap<&'static str, Symbol>,
999 strings: Vec<&'static str>,
1000 gensyms: Vec<Symbol>,
1004 fn prefill(init: &[&'static str]) -> Self {
1006 strings: init.into(),
1007 names: init.iter().copied().zip((0..).map(Symbol::new)).collect(),
1008 ..Default::default()
1012 pub fn intern(&mut self, string: &str) -> Symbol {
1013 if let Some(&name) = self.names.get(string) {
1017 let name = Symbol::new(self.strings.len() as u32);
1019 // `from_utf8_unchecked` is safe since we just allocated a `&str` which is known to be
1021 let string: &str = unsafe {
1022 str::from_utf8_unchecked(self.arena.alloc_slice(string.as_bytes()))
1024 // It is safe to extend the arena allocation to `'static` because we only access
1025 // these while the arena is still alive.
1026 let string: &'static str = unsafe {
1027 &*(string as *const str)
1029 self.strings.push(string);
1030 self.names.insert(string, name);
1034 fn interned(&self, symbol: Symbol) -> Symbol {
1035 if (symbol.0.as_usize()) < self.strings.len() {
1038 self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize]
1042 fn gensymed(&mut self, symbol: Symbol) -> Symbol {
1043 self.gensyms.push(symbol);
1044 Symbol::new(SymbolIndex::MAX_AS_U32 - self.gensyms.len() as u32 + 1)
1047 fn is_gensymed(&mut self, symbol: Symbol) -> bool {
1048 symbol.0.as_usize() >= self.strings.len()
1051 // Get the symbol as a string. `Symbol::as_str()` should be used in
1052 // preference to this function.
1053 pub fn get(&self, symbol: Symbol) -> &str {
1054 match self.strings.get(symbol.0.as_usize()) {
1055 Some(string) => string,
1057 let symbol = self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize];
1058 self.strings[symbol.0.as_usize()]
1064 // This module has a very short name because it's used a lot.
1070 // This module has a very short name because it's used a lot.
1072 use std::convert::TryInto;
1077 // Get the symbol for an integer. The first few non-negative integers each
1078 // have a static symbol and therefore are fast.
1079 pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
1080 if let Result::Ok(idx) = n.try_into() {
1081 if let Option::Some(&sym) = digits_array.get(idx) {
1085 Symbol::intern(&n.to_string())
1090 fn is_used_keyword_2018(self) -> bool {
1091 self >= kw::Async && self <= kw::Dyn
1094 fn is_unused_keyword_2018(self) -> bool {
1098 /// Used for sanity checking rustdoc keyword sections.
1099 pub fn is_doc_keyword(self) -> bool {
1103 /// A keyword or reserved identifier that can be used as a path segment.
1104 pub fn is_path_segment_keyword(self) -> bool {
1105 self == kw::Super ||
1106 self == kw::SelfLower ||
1107 self == kw::SelfUpper ||
1108 self == kw::Crate ||
1109 self == kw::PathRoot ||
1110 self == kw::DollarCrate
1113 /// Returns `true` if the symbol is `true` or `false`.
1114 pub fn is_bool_lit(self) -> bool {
1115 self == kw::True || self == kw::False
1118 /// This symbol can be a raw identifier.
1119 pub fn can_be_raw(self) -> bool {
1120 self != kw::Invalid && self != kw::Underscore && !self.is_path_segment_keyword()
1125 // Returns `true` for reserved identifiers used internally for elided lifetimes,
1126 // unnamed method parameters, crate root module, error recovery etc.
1127 pub fn is_special(self) -> bool {
1128 self.name <= kw::Underscore
1131 /// Returns `true` if the token is a keyword used in the language.
1132 pub fn is_used_keyword(self) -> bool {
1133 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1134 self.name >= kw::As && self.name <= kw::While ||
1135 self.name.is_used_keyword_2018() && self.span.rust_2018()
1138 /// Returns `true` if the token is a keyword reserved for possible future use.
1139 pub fn is_unused_keyword(self) -> bool {
1140 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1141 self.name >= kw::Abstract && self.name <= kw::Yield ||
1142 self.name.is_unused_keyword_2018() && self.span.rust_2018()
1145 /// Returns `true` if the token is either a special identifier or a keyword.
1146 pub fn is_reserved(self) -> bool {
1147 self.is_special() || self.is_used_keyword() || self.is_unused_keyword()
1150 /// A keyword or reserved identifier that can be used as a path segment.
1151 pub fn is_path_segment_keyword(self) -> bool {
1152 self.name.is_path_segment_keyword()
1155 /// We see this identifier in a normal identifier position, like variable name or a type.
1156 /// How was it written originally? Did it use the raw form? Let's try to guess.
1157 pub fn is_raw_guess(self) -> bool {
1158 self.name.can_be_raw() && self.is_reserved()
1162 // If an interner exists, return it. Otherwise, prepare a fresh one.
1164 fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
1165 GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock()))
1168 /// An alternative to `Symbol` and `InternedString`, useful when the chars
1169 /// within the symbol need to be accessed. It is best used for temporary
1172 /// Because the interner outlives any thread which uses this type, we can
1173 /// safely treat `string` which points to interner data, as an immortal string,
1174 /// as long as this type never crosses between threads.
1176 // FIXME: ensure that the interner outlives any thread which uses
1177 // `LocalInternedString`, by creating a new thread right after constructing the
1179 #[derive(Clone, Copy, Eq, PartialOrd, Ord)]
1180 pub struct LocalInternedString {
1181 string: &'static str,
1184 impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
1186 str: std::convert::AsRef<U>
1189 fn as_ref(&self) -> &U {
1190 self.string.as_ref()
1194 impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString {
1195 fn eq(&self, other: &T) -> bool {
1196 self.string == other.deref()
1200 impl std::cmp::PartialEq<LocalInternedString> for str {
1201 fn eq(&self, other: &LocalInternedString) -> bool {
1202 self == other.string
1206 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a str {
1207 fn eq(&self, other: &LocalInternedString) -> bool {
1208 *self == other.string
1212 impl std::cmp::PartialEq<LocalInternedString> for String {
1213 fn eq(&self, other: &LocalInternedString) -> bool {
1214 self == other.string
1218 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a String {
1219 fn eq(&self, other: &LocalInternedString) -> bool {
1220 *self == other.string
1224 impl !Send for LocalInternedString {}
1225 impl !Sync for LocalInternedString {}
1227 impl std::ops::Deref for LocalInternedString {
1230 fn deref(&self) -> &str { self.string }
1233 impl fmt::Debug for LocalInternedString {
1234 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1235 fmt::Debug::fmt(self.string, f)
1239 impl fmt::Display for LocalInternedString {
1240 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1241 fmt::Display::fmt(self.string, f)
1245 /// An alternative to `Symbol` that is focused on string contents. It has two
1246 /// main differences to `Symbol`.
1248 /// First, its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1249 /// string chars rather than the symbol integer. This is useful when hash
1250 /// stability is required across compile sessions, or a guaranteed sort
1251 /// ordering is required.
1253 /// Second, gensym-ness is irrelevant. E.g.:
1255 /// assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))
1256 /// assert_eq!(Symbol::gensym("x").as_interned_str(), Symbol::gensym("x").as_interned_str())
1258 #[derive(Clone, Copy, PartialEq, Eq)]
1259 pub struct InternedString {
1263 impl InternedString {
1264 /// Maps a string to its interned representation.
1265 pub fn intern(string: &str) -> Self {
1267 symbol: Symbol::intern(string)
1271 pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
1275 fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: &InternedString, f: F) -> R {
1276 self.symbol.with2(other.symbol, f)
1279 pub fn as_symbol(self) -> Symbol {
1283 /// Convert to a `LocalInternedString`. This is a slowish operation because it
1284 /// requires locking the symbol interner.
1285 pub fn as_str(self) -> LocalInternedString {
1286 self.symbol.as_str()
1290 impl Hash for InternedString {
1291 fn hash<H: Hasher>(&self, state: &mut H) {
1292 self.with(|str| str.hash(state))
1296 impl PartialOrd<InternedString> for InternedString {
1297 fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
1298 if self.symbol == other.symbol {
1299 return Some(Ordering::Equal);
1301 self.with2(other, |self_str, other_str| self_str.partial_cmp(other_str))
1305 impl Ord for InternedString {
1306 fn cmp(&self, other: &InternedString) -> Ordering {
1307 if self.symbol == other.symbol {
1308 return Ordering::Equal;
1310 self.with2(other, |self_str, other_str| self_str.cmp(other_str))
1314 impl fmt::Debug for InternedString {
1315 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1316 self.with(|str| fmt::Debug::fmt(&str, f))
1320 impl fmt::Display for InternedString {
1321 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1322 self.with(|str| fmt::Display::fmt(&str, f))
1326 impl Decodable for InternedString {
1327 fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
1328 Ok(InternedString::intern(&d.read_str()?))
1332 impl Encodable for InternedString {
1333 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
1334 self.with(|string| s.emit_str(string))