]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/tools.rs: Add AsAyn Trait
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 8 May 2019 09:05:38 +0000 (11:05 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 8 May 2019 09:07:36 +0000 (11:07 +0200)
src/api_schema/router.rs
src/tools.rs

index a2605e19fef05a2ea2f67edbe98632e94a41aa39..c6b7795348648d721d9f17d3786f37894c4201bc 100644 (file)
@@ -15,7 +15,7 @@ use super::api_handler::*;
 pub type BoxFut = Box<Future<Item = Response<Body>, Error = failure::Error> + Send>;
 
 /// Abstract Interface for API methods to interact with the environment
-pub trait RpcEnvironment {
+pub trait RpcEnvironment: std::any::Any + crate::tools::AsAny + Send {
 
     /// Use this to pass additional result data. It is up to the environment
     /// how the data is used.
index 54a7703d6a271be6af33f56e0a73f0f4ee3a7d15..c887b3cfb6149252b7b94768cf3f000c5350eb7a 100644 (file)
@@ -13,6 +13,7 @@ use std::path::Path;
 use std::io::Read;
 use std::io::ErrorKind;
 use std::time::Duration;
+use std::any::Any;
 
 use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
 
@@ -711,3 +712,14 @@ pub fn pipe() -> Result<(Fd, Fd), Error> {
     let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?;
     Ok((Fd(pin), Fd(pout)))
 }
+
+/// An easy way to convert types to Any
+///
+/// Mostly useful to downcast trait objects (see RpcEnvironment).
+pub trait AsAny {
+    fn as_any(&self) -> &Any;
+}
+
+impl<T: Any> AsAny for T {
+    fn as_any(&self) -> &Any { self }
+}