use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
pub trait LoadingQuery {
fn state(&self) -> LoadingState;
fn progress(&self) -> Option<LoadProgress>;
fn final_url(&self) -> Option<&str>;
fn redirect_chain(&self) -> &[String];
fn mime(&self) -> Option<&str>;
fn tls_summary(&self) -> Option<&TlsSummary>;
fn cache_origin(&self) -> CacheOrigin;
fn error(&self) -> Option<&LoadError>;
}
#[derive(
Clone, Copy, Debug, Default, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize,
)]
pub enum LoadingState {
#[default]
Pending,
InProgress,
Done,
Failed,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub struct LoadProgress {
pub bytes_received: u64,
pub bytes_total: Option<u64>,
}
#[derive(Clone, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub struct TlsSummary {
pub protocol: String, pub cipher_suite: String,
pub validated: bool,
pub host: String,
}
#[derive(
Clone, Copy, Debug, Default, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize,
)]
pub enum CacheOrigin {
CacheHit,
#[default]
CacheMiss,
NotCacheable,
}
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub struct LoadError {
pub kind: LoadErrorKind,
pub message: String,
}
#[derive(
Clone, Copy, Debug, Default, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize,
)]
pub enum LoadErrorKind {
Network,
TlsHandshake,
ServerError,
Decoding,
#[default]
Other,
}