Merge branch 'main' into gpui2

This commit is contained in:
Marshall Bowers
2023-10-07 10:50:05 -04:00
852 changed files with 30583 additions and 13887 deletions
+14
View File
@@ -41,6 +41,8 @@ pub fn truncate(s: &str, max_chars: usize) -> &str {
}
}
/// Removes characters from the end of the string if it's length is greater than `max_chars` and
/// appends "..." to the string. Returns string unchanged if it's length is smaller than max_chars.
pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
debug_assert!(max_chars >= 5);
@@ -51,6 +53,18 @@ pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
}
}
/// Removes characters from the front of the string if it's length is greater than `max_chars` and
/// prepends the string with "...". Returns string unchanged if it's length is smaller than max_chars.
pub fn truncate_and_remove_front(s: &str, max_chars: usize) -> String {
debug_assert!(max_chars >= 5);
let truncation_ix = s.char_indices().map(|(i, _)| i).nth_back(max_chars);
match truncation_ix {
Some(length) => "…".to_string() + &s[length..],
None => s.to_string(),
}
}
pub fn post_inc<T: From<u8> + AddAssign<T> + Copy>(value: &mut T) -> T {
let prev = *value;
*value += T::from(1);