1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod connection;
pub mod global;
pub mod interface;
pub mod object;
pub mod protocol;
pub mod proxy;
pub mod wire;
mod socket;
pub use wayrs_scanner as scanner;
use std::ffi::CStr;
use std::io;
#[derive(Debug, thiserror::Error)]
pub enum ConnectError {
#[error("both $XDG_RUNTIME_DIR and $WAYLAND_DISPLAY must by set")]
NotEnoughEnvVars,
#[error(transparent)]
Io(#[from] io::Error),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IoMode {
Blocking,
NonBlocking,
}
#[macro_export]
macro_rules! cstr {
($str:literal) => {{
const X: &'static ::std::ffi::CStr = $crate::cstr(concat!($str, "\0"));
X
}};
}
#[doc(hidden)]
pub const fn cstr(string: &str) -> &CStr {
let bytes = string.as_bytes();
let mut i = 0;
while i < bytes.len() {
let byte = bytes[i];
assert!((byte != 0 && i + 1 != bytes.len()) || (byte == 0 && i + 1 == bytes.len()));
i += 1;
}
unsafe { CStr::from_bytes_with_nul_unchecked(bytes) }
}