Omit default parameter types

This commit is contained in:
Kirill Bulatov 2019-12-08 00:54:18 +02:00
parent 8dd0e0086f
commit 14c167a9f6
12 changed files with 150 additions and 29 deletions

View file

@ -9,7 +9,7 @@ pub struct HirFormatter<'a, 'b, DB> {
fmt: &'a mut fmt::Formatter<'b>,
buf: String,
curr_size: usize,
max_size: Option<usize>,
truncate_options: Option<&'a TruncateOptions>,
}
pub trait HirDisplay {
@ -25,12 +25,12 @@ pub trait HirDisplay {
fn display_truncated<'a, DB>(
&'a self,
db: &'a DB,
max_size: Option<usize>,
truncate_options: &'a TruncateOptions,
) -> HirDisplayWrapper<'a, DB, Self>
where
Self: Sized,
{
HirDisplayWrapper(db, self, max_size)
HirDisplayWrapper(db, self, Some(truncate_options))
}
}
@ -66,15 +66,24 @@ where
}
pub fn should_truncate(&self) -> bool {
if let Some(max_size) = self.max_size {
if let Some(max_size) = self.truncate_options.and_then(|options| options.max_length) {
self.curr_size >= max_size
} else {
false
}
}
pub fn should_display_default_types(&self) -> bool {
self.truncate_options.map(|options| options.show_default_types).unwrap_or(true)
}
}
pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>);
pub struct TruncateOptions {
pub max_length: Option<usize>,
pub show_default_types: bool,
}
pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<&'a TruncateOptions>);
impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T>
where
@ -87,7 +96,7 @@ where
fmt: f,
buf: String::with_capacity(20),
curr_size: 0,
max_size: self.2,
truncate_options: self.2,
})
}
}