+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
+crate enum UrlFragment {
+ Method(Symbol),
+ TyMethod(Symbol),
+ AssociatedConstant(Symbol),
+ AssociatedType(Symbol),
+
+ StructField(Symbol),
+ Variant(Symbol),
+ VariantField { variant: Symbol, field: Symbol },
+
+ UserWritten(String),
+}
+
+impl UrlFragment {
+ /// Create a fragment for an associated item.
+ ///
+ /// `is_prototype` is whether this associated item is a trait method
+ /// without a default definition.
+ fn from_assoc_item(name: Symbol, kind: ty::AssocKind, is_prototype: bool) -> Self {
+ match kind {
+ ty::AssocKind::Fn => {
+ if is_prototype {
+ UrlFragment::TyMethod(name)
+ } else {
+ UrlFragment::Method(name)
+ }
+ }
+ ty::AssocKind::Const => UrlFragment::AssociatedConstant(name),
+ ty::AssocKind::Type => UrlFragment::AssociatedType(name),
+ }
+ }
+}
+
+/// Render the fragment, including the leading `#`.
+impl std::fmt::Display for UrlFragment {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "#")?;
+ match self {
+ UrlFragment::Method(name) => write!(f, "method.{}", name),
+ UrlFragment::TyMethod(name) => write!(f, "tymethod.{}", name),
+ UrlFragment::AssociatedConstant(name) => write!(f, "associatedconstant.{}", name),
+ UrlFragment::AssociatedType(name) => write!(f, "associatedtype.{}", name),
+ UrlFragment::StructField(name) => write!(f, "structfield.{}", name),
+ UrlFragment::Variant(name) => write!(f, "variant.{}", name),
+ UrlFragment::VariantField { variant, field } => {
+ write!(f, "variant.{}.field.{}", variant, field)
+ }
+ UrlFragment::UserWritten(raw) => write!(f, "{}", raw),
+ }
+ }
+}
+