Skip to content

Commit

Permalink
implement some more type label todos
Browse files Browse the repository at this point in the history
  • Loading branch information
wfraser committed Nov 25, 2023
1 parent cca6de3 commit ae12c76
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/browser_rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,33 @@ fn type_label(ty: &rustdoc_types::Type) -> String {
types.iter().map(type_label).collect::<Vec<_>>().join(", ")),
Slice(ty) => format!("&[{}]", type_label(ty)),
Array { type_, len } => format!("[{}; {len}]", type_label(type_)),
ImplTrait(_) => todo!(),
ImplTrait(t) => {
use rustdoc_types::GenericBound::*;
format!("impl {}",
t.iter()
.map(|g| match g {
TraitBound { trait_, .. } => trait_.name.as_str(),
Outlives(o) => o.as_str(),
})
.collect::<Vec<_>>()
.join(" + "),
)
}
Infer => "_".to_owned(),
RawPointer { mutable, type_ } => todo!(),
BorrowedRef { lifetime, mutable, type_ } => todo!(),
QualifiedPath { name, args, self_type, trait_ } => {
RawPointer { mutable, type_ } => {
format!("*{} {}",
if *mutable { "mut" } else { "const" },
type_label(type_),
)
},
BorrowedRef { lifetime, mutable, type_ } => {
format!("&{}{} {}",
lifetime.as_deref().unwrap_or_default(),
if *mutable { "mut" } else { "" },
type_label(type_),
)
},
QualifiedPath { name, args:_ , self_type, trait_ } => {
if let Some(trait_) = trait_ {
format!("<{} as {}>::{name}", type_label(self_type), trait_.name)
} else {
Expand Down

0 comments on commit ae12c76

Please sign in to comment.