diff options
author | Kirill Bulatov <[email protected]> | 2019-12-19 14:43:41 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2019-12-19 14:43:41 +0000 |
commit | 4ed78f80f4cc3cf32681fce6722293da6c8df76d (patch) | |
tree | 217f9900f114bdb2298a3c29ab16747d53805ebe /crates/ra_hir_ty/src | |
parent | 4fb25ef43bd96da94467ffa4de8fbf0af82b28d1 (diff) |
Remove TruncateOptions struct
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 9176c0629..dcca1bace 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs | |||
@@ -9,7 +9,8 @@ pub struct HirFormatter<'a, 'b, DB> { | |||
9 | fmt: &'a mut fmt::Formatter<'b>, | 9 | fmt: &'a mut fmt::Formatter<'b>, |
10 | buf: String, | 10 | buf: String, |
11 | curr_size: usize, | 11 | curr_size: usize, |
12 | truncate_options: Option<&'a TruncateOptions>, | 12 | max_size: Option<usize>, |
13 | should_display_default_types: bool, | ||
13 | } | 14 | } |
14 | 15 | ||
15 | pub trait HirDisplay { | 16 | pub trait HirDisplay { |
@@ -19,18 +20,18 @@ pub trait HirDisplay { | |||
19 | where | 20 | where |
20 | Self: Sized, | 21 | Self: Sized, |
21 | { | 22 | { |
22 | HirDisplayWrapper(db, self, None) | 23 | HirDisplayWrapper(db, self, None, true) |
23 | } | 24 | } |
24 | 25 | ||
25 | fn display_truncated<'a, DB>( | 26 | fn display_truncated<'a, DB>( |
26 | &'a self, | 27 | &'a self, |
27 | db: &'a DB, | 28 | db: &'a DB, |
28 | truncate_options: &'a TruncateOptions, | 29 | max_size: Option<usize>, |
29 | ) -> HirDisplayWrapper<'a, DB, Self> | 30 | ) -> HirDisplayWrapper<'a, DB, Self> |
30 | where | 31 | where |
31 | Self: Sized, | 32 | Self: Sized, |
32 | { | 33 | { |
33 | HirDisplayWrapper(db, self, Some(truncate_options)) | 34 | HirDisplayWrapper(db, self, max_size, false) |
34 | } | 35 | } |
35 | } | 36 | } |
36 | 37 | ||
@@ -66,7 +67,7 @@ where | |||
66 | } | 67 | } |
67 | 68 | ||
68 | pub fn should_truncate(&self) -> bool { | 69 | pub fn should_truncate(&self) -> bool { |
69 | if let Some(max_size) = self.truncate_options.and_then(|options| options.max_length) { | 70 | if let Some(max_size) = self.max_size { |
70 | self.curr_size >= max_size | 71 | self.curr_size >= max_size |
71 | } else { | 72 | } else { |
72 | false | 73 | false |
@@ -74,16 +75,11 @@ where | |||
74 | } | 75 | } |
75 | 76 | ||
76 | pub fn should_display_default_types(&self) -> bool { | 77 | pub fn should_display_default_types(&self) -> bool { |
77 | self.truncate_options.map(|options| options.show_default_types).unwrap_or(true) | 78 | self.should_display_default_types |
78 | } | 79 | } |
79 | } | 80 | } |
80 | 81 | ||
81 | pub struct TruncateOptions { | 82 | pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>, bool); |
82 | pub max_length: Option<usize>, | ||
83 | pub show_default_types: bool, | ||
84 | } | ||
85 | |||
86 | pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<&'a TruncateOptions>); | ||
87 | 83 | ||
88 | impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T> | 84 | impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T> |
89 | where | 85 | where |
@@ -96,7 +92,8 @@ where | |||
96 | fmt: f, | 92 | fmt: f, |
97 | buf: String::with_capacity(20), | 93 | buf: String::with_capacity(20), |
98 | curr_size: 0, | 94 | curr_size: 0, |
99 | truncate_options: self.2, | 95 | max_size: self.2, |
96 | should_display_default_types: self.3, | ||
100 | }) | 97 | }) |
101 | } | 98 | } |
102 | } | 99 | } |