From e28a6dfaabc8f19d06f7be2c68e513da2e7d5735 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 23 Sep 2019 11:36:52 -0700 Subject: [PATCH] Provide some default trait implementations We cannot expect every backend to support GET_CONFIG and SET_CONFIG commands. That's why this patch adds some default implementations for the trait VhostUserBackend regarding both get_config() and set_config() functions. Signed-off-by: Cathy Zhang Signed-off-by: Sebastien Boeuf --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 676e222..65a89b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,10 +85,18 @@ pub trait VhostUserBackend: Send + Sync + 'static { ) -> result::Result; /// Get virtio device configuration. - fn get_config(&self, offset: u32, size: u32) -> Vec; + /// A default implementation is provided as we cannot expect all backends + /// to implement this function. + fn get_config(&self, offset: u32, size: u32) -> Vec { + Vec::new() + } /// Set virtio device configuration. - fn set_config(&mut self, offset: u32, buf: &[u8]) -> result::Result<(), io::Error>; + /// A default implementation is provided as we cannot expect all backends + /// to implement this function. + fn set_config(&mut self, offset: u32, buf: &[u8]) -> result::Result<(), io::Error> { + Ok(()) + } } /// This structure is the public API the backend is allowed to interact with