use log::trace;
use url::Url;
use crate::{
coroutine::*,
rfc4918::{
Property, WebdavAuth, proppatch_body,
request::WebdavRequest,
send::{SendError, SendRaw},
},
webdav_try,
};
#[derive(Debug)]
pub struct Proppatch {
state: State,
}
impl Proppatch {
pub fn new(
base_url: &Url,
auth: &WebdavAuth,
user_agent: &str,
path: &str,
set: &[(Property, &str)],
) -> Self {
let request = WebdavRequest::proppatch(base_url, auth, user_agent, path)
.content_type_xml()
.body(proppatch_body(set));
Self {
state: State::Send(SendRaw::new(request)),
}
}
}
impl WebdavCoroutine for Proppatch {
type Yield = WebdavYield;
type Return = Result<(), SendError>;
fn resume(&mut self, arg: Option<&[u8]>) -> WebdavCoroutineState<Self::Yield, Self::Return> {
trace!("sending request");
match &mut self.state {
State::Send(send) => {
webdav_try!(send, arg);
WebdavCoroutineState::Complete(Ok(()))
}
}
}
}
#[derive(Debug)]
enum State {
Send(SendRaw),
}