mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
generalize documentation, make the name shorter
It's more useful than just *debug* logs, but yes, should not be relied upon for logic reasons.
This commit is contained in:
parent
08cd8f19e3
commit
6aca128547
2 changed files with 16 additions and 22 deletions
|
|
@ -34,7 +34,7 @@ use super::pdu::PduBuilder;
|
|||
use crate::{
|
||||
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
||||
services,
|
||||
utils::{self, truncate_str_for_debug},
|
||||
utils::{self, dbg_truncate_str},
|
||||
Error, PduEvent, Result,
|
||||
};
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ impl Service {
|
|||
#[tracing::instrument(
|
||||
skip(self, room_message),
|
||||
fields(
|
||||
room_message = truncate_str_for_debug(&room_message, 50).as_ref(),
|
||||
room_message = dbg_truncate_str(&room_message, 50).as_ref(),
|
||||
),
|
||||
)]
|
||||
pub(crate) fn process_message(&self, room_message: String) {
|
||||
|
|
@ -306,7 +306,7 @@ impl Service {
|
|||
#[tracing::instrument(
|
||||
skip(self, room_message),
|
||||
fields(
|
||||
room_message = truncate_str_for_debug(&room_message, 50).as_ref(),
|
||||
room_message = dbg_truncate_str(&room_message, 50).as_ref(),
|
||||
),
|
||||
)]
|
||||
async fn process_admin_message(
|
||||
|
|
@ -357,7 +357,7 @@ impl Service {
|
|||
#[tracing::instrument(
|
||||
skip(command_line),
|
||||
fields(
|
||||
command_line = truncate_str_for_debug(command_line, 50).as_ref(),
|
||||
command_line = dbg_truncate_str(command_line, 50).as_ref(),
|
||||
),
|
||||
)]
|
||||
fn parse_admin_command(
|
||||
|
|
|
|||
30
src/utils.rs
30
src/utils.rs
|
|
@ -228,11 +228,8 @@ pub(crate) fn debug_slice_truncated<T: fmt::Debug>(
|
|||
/// Truncates a string to an approximate maximum length, replacing any extra
|
||||
/// text with an ellipsis.
|
||||
///
|
||||
/// Only to be used for debug logging, exact semantics are unspecified.
|
||||
pub(crate) fn truncate_str_for_debug(
|
||||
s: &str,
|
||||
mut max_len: usize,
|
||||
) -> Cow<'_, str> {
|
||||
/// Only to be used for informational purposes, exact semantics are unspecified.
|
||||
pub(crate) fn dbg_truncate_str(s: &str, mut max_len: usize) -> Cow<'_, str> {
|
||||
while max_len < s.len() && !s.is_char_boundary(max_len) {
|
||||
max_len += 1;
|
||||
}
|
||||
|
|
@ -247,21 +244,18 @@ pub(crate) fn truncate_str_for_debug(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::truncate_str_for_debug;
|
||||
use crate::utils::dbg_truncate_str;
|
||||
|
||||
#[test]
|
||||
fn test_truncate_str_for_debug() {
|
||||
assert_eq!(truncate_str_for_debug("short", 10), "short");
|
||||
assert_eq!(
|
||||
truncate_str_for_debug("very long string", 10),
|
||||
"very long ..."
|
||||
);
|
||||
assert_eq!(truncate_str_for_debug("no info, only dots", 0), "...");
|
||||
assert_eq!(truncate_str_for_debug("", 0), "");
|
||||
assert_eq!(truncate_str_for_debug("unicöde", 5), "unicö...");
|
||||
fn test_truncate_str() {
|
||||
assert_eq!(dbg_truncate_str("short", 10), "short");
|
||||
assert_eq!(dbg_truncate_str("very long string", 10), "very long ...");
|
||||
assert_eq!(dbg_truncate_str("no info, only dots", 0), "...");
|
||||
assert_eq!(dbg_truncate_str("", 0), "");
|
||||
assert_eq!(dbg_truncate_str("unicöde", 5), "unicö...");
|
||||
let ok_hand = "👌🏽";
|
||||
assert_eq!(truncate_str_for_debug(ok_hand, 1), "👌...");
|
||||
assert_eq!(truncate_str_for_debug(ok_hand, ok_hand.len() - 1), "👌🏽");
|
||||
assert_eq!(truncate_str_for_debug(ok_hand, ok_hand.len()), "👌🏽");
|
||||
assert_eq!(dbg_truncate_str(ok_hand, 1), "👌...");
|
||||
assert_eq!(dbg_truncate_str(ok_hand, ok_hand.len() - 1), "👌🏽");
|
||||
assert_eq!(dbg_truncate_str(ok_hand, ok_hand.len()), "👌🏽");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue