mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 12:35:26 +00:00
In Rust 2018 edition, `extern crate` is no longer required for importing from other crates. Instead of writing: extern crate dep; use dep::Thing; we write: use dep::Thing; In this approach, macros are imported individually from the declaring crate rather than through #[macro_use]. Before: #[macro_use] extern crate sys_util; After: use sys_util::{debug, error}; The only place that `extern crate` continues to be required is in importing the compiler's proc_macro API into a procedural macro crate. This will hopefully be fixed in a future Rust release. extern crate proc_macro; TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293 Reviewed-on: https://chromium-review.googlesource.com/1565302 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
use sys_util::EventFd;
|
|
|
|
use msg_socket::*;
|
|
|
|
#[derive(MsgOnSocket)]
|
|
struct DummyRequest {}
|
|
|
|
#[derive(MsgOnSocket)]
|
|
enum Response {
|
|
A(u8),
|
|
B,
|
|
C(u32, EventFd),
|
|
D([u8; 4]),
|
|
E { f0: u8, f1: u32 },
|
|
}
|
|
|
|
#[test]
|
|
fn sock_send_recv_enum() {
|
|
let (req, res) = pair::<DummyRequest, Response>().unwrap();
|
|
let e0 = EventFd::new().unwrap();
|
|
let e1 = e0.try_clone().unwrap();
|
|
res.send(&Response::C(0xf0f0, e0)).unwrap();
|
|
let r = req.recv().unwrap();
|
|
match r {
|
|
Response::C(v, efd) => {
|
|
assert_eq!(v, 0xf0f0);
|
|
efd.write(0x0f0f).unwrap();
|
|
}
|
|
_ => panic!("wrong type"),
|
|
};
|
|
assert_eq!(e1.read().unwrap(), 0x0f0f);
|
|
|
|
res.send(&Response::B).unwrap();
|
|
match req.recv().unwrap() {
|
|
Response::B => {}
|
|
_ => panic!("Wrong enum type"),
|
|
};
|
|
|
|
res.send(&Response::A(0x3)).unwrap();
|
|
match req.recv().unwrap() {
|
|
Response::A(v) => assert_eq!(v, 0x3),
|
|
_ => panic!("Wrong enum type"),
|
|
};
|
|
|
|
res.send(&Response::D([0, 1, 2, 3])).unwrap();
|
|
match req.recv().unwrap() {
|
|
Response::D(v) => assert_eq!(v, [0, 1, 2, 3]),
|
|
_ => panic!("Wrong enum type"),
|
|
};
|
|
|
|
res.send(&Response::E {
|
|
f0: 0x12,
|
|
f1: 0x0f0f,
|
|
})
|
|
.unwrap();
|
|
match req.recv().unwrap() {
|
|
Response::E { f0, f1 } => {
|
|
assert_eq!(f0, 0x12);
|
|
assert_eq!(f1, 0x0f0f);
|
|
}
|
|
_ => panic!("Wrong enum type"),
|
|
};
|
|
}
|