use std::path::PathBuf; use http::Uri; use tokio::sync::oneshot; use crate::client_new::DownloadState; use super::error::ClientActorError; type ActionIndex = u64; pub(super) type DownloadResult = Result; #[derive(Debug)] pub(super) enum ClientActorMessage { Download { filename: PathBuf, uri: Uri, respond_to: oneshot::Sender, }, GetData { uri: Uri, respond_to: oneshot::Sender>>, }, } #[derive(Clone, Debug)] pub(super) enum ClientActorMessageHandle { Download { filename: PathBuf, uri: Uri, state: DownloadState, message: ActionIndex, }, GetData { uri: Uri, buffer: Option>, message: ActionIndex, }, } impl ClientActorMessageHandle { pub(super) fn set_state(&mut self, new_state: DownloadState) { match self { Self::Download { ref mut state, .. } => *state = new_state, _ => panic!("Called with invalid variant"), }; } pub(super) fn filename(&self) -> PathBuf { match self { Self::Download { ref filename, .. } => filename.clone(), _ => panic!("Called with invalid variant"), } } pub(super) fn uri(&self) -> Uri { match self { Self::Download { ref uri, .. } => uri.clone(), Self::GetData { ref uri, .. } => uri.clone(), } } pub(super) fn buffer_mut(&mut self) -> &mut Option> { match self { Self::GetData { ref mut buffer, .. } => buffer, _ => panic!("Called with invalid variant"), } } }