Add format_constness() and last_line_used_width()
This commit is contained in:
parent
c283d3e643
commit
14f416273b
18
src/utils.rs
18
src/utils.rs
@ -56,6 +56,14 @@ pub fn format_visibility(vis: &Visibility) -> Cow<'static, str> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn format_constness(constness: ast::Constness) -> &'static str {
|
||||||
|
match constness {
|
||||||
|
ast::Constness::Const => "const ",
|
||||||
|
ast::Constness::NotConst => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn format_defaultness(defaultness: ast::Defaultness) -> &'static str {
|
pub fn format_defaultness(defaultness: ast::Defaultness) -> &'static str {
|
||||||
match defaultness {
|
match defaultness {
|
||||||
@ -107,6 +115,16 @@ pub fn last_line_width(s: &str) -> usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The total used width of the last line.
|
||||||
|
#[inline]
|
||||||
|
pub fn last_line_used_width(s: &str, offset: usize) -> usize {
|
||||||
|
if s.contains('\n') {
|
||||||
|
last_line_width(s)
|
||||||
|
} else {
|
||||||
|
offset + s.len()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn trimmed_last_line_width(s: &str) -> usize {
|
pub fn trimmed_last_line_width(s: &str) -> usize {
|
||||||
match s.rfind('\n') {
|
match s.rfind('\n') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user