btrfs2/linux/ctypes/
ioctl_device_path.rs

1use linux::imports::*;
2
3#[ repr (C) ]
4#[ derive (Copy) ]
5pub struct IoctlDevicePath {
6	pub path: [u8; DEVICE_PATH_NAME_MAX],
7}
8
9impl IoctlDevicePath {
10
11	pub fn as_vec (
12		& self,
13	) -> Vec <u8> {
14
15		self.path.iter ().cloned ().take_while (
16			|item|
17			* item != 0
18		).collect ()
19
20	}
21
22	pub fn as_os_string (
23		& self,
24	) -> OsString {
25
26		OsString::from_vec (
27			self.as_vec ())
28
29	}
30
31}
32
33impl Clone for IoctlDevicePath {
34
35	fn clone (
36		& self,
37	) -> Self {
38
39		IoctlDevicePath {
40			path: self.path,
41		}
42
43	}
44
45	fn clone_from (
46		& mut self,
47		source: & Self,
48	) {
49
50		self.path.clone_from_slice (
51			& source.path)
52
53	}
54
55}
56
57impl fmt::Debug for IoctlDevicePath {
58
59	fn fmt (
60		& self,
61		formatter: & mut fmt::Formatter,
62	) -> fmt::Result {
63
64		let string_bytes =
65			self.as_vec ();
66
67		let rust_string =
68			String::from_utf8_lossy (
69				& string_bytes);
70
71		rust_string.fmt (
72			formatter)
73
74	}
75
76}
77
78// ex: noet ts=4 filetype=rust