mirror of
https://github.com/servo/servo.git
synced 2025-07-08 16:03:40 +01:00
Truncate long URLs when doing debug prints
I added the required changes on debug in lib.rs file, you can have a review
This commit is contained in:
parent
4b091ef59b
commit
abc5b2a5bc
1 changed files with 8 additions and 0 deletions
|
@ -17,7 +17,9 @@ pub mod origin;
|
|||
|
||||
pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin};
|
||||
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::fmt;
|
||||
use std::hash::Hasher;
|
||||
use std::net::IpAddr;
|
||||
use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo};
|
||||
use std::path::Path;
|
||||
|
@ -169,6 +171,12 @@ impl fmt::Display for ServoUrl {
|
|||
|
||||
impl fmt::Debug for ServoUrl {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.0.as_str().len() > 40 {
|
||||
let hasher = DefaultHasher::new();
|
||||
let truncated: String = self.0.as_str().chars().take(40).collect();
|
||||
let result = format!("{}... ({})", truncated, hasher.finish().to_string());
|
||||
return result.fmt(formatter);
|
||||
}
|
||||
self.0.fmt(formatter)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue