sftp_protocol/packet/
rmdir.rs

1use camino::Utf8PathBuf;
2
3use super::kind::PacketType;
4use super::PayloadTrait;
5
6#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
7#[nom(BigEndian)]
8#[cfg_attr(test, derive(test_strategy::Arbitrary))]
9pub struct RmDir {
10	pub id: u32,
11	#[nom(Parse(crate::util::parse_path))]
12	#[serde(serialize_with = "crate::util::path_with_u32_length")]
13	pub path: Utf8PathBuf
14}
15
16impl PayloadTrait for RmDir {
17	const Type: PacketType = PacketType::RmDir;
18	fn binsize(&self) -> u32 {
19		4 + 4 + self.path.as_str().len() as u32
20	}
21}
22
23impl From<RmDir> for super::Payload {
24	fn from(p: RmDir) -> Self {
25		Self::RmDir(p)
26	}
27}
28
29#[cfg(test)]
30mod tests {
31	use test_strategy::proptest;
32	use crate::parser::encode;
33	use crate::parser::Parser;
34	use super::*;
35
36	#[proptest]
37	fn roundtrip_whole(input: RmDir) {
38		let mut stream = Parser::default();
39		let packet = input.into_packet();
40		stream.write(&encode(&packet)).unwrap();
41		assert_eq!(stream.get_packet(), Ok(Some(packet)));
42		assert_eq!(stream.get_packet(), Ok(None));
43	}
44}
45