Trait PluginHandler

Source
pub trait PluginHandler<B: Backend> {
    type CreateArgs: Args;
    type Create: Create<B>;
    type Open: Open<B>;

Show 21 methods // Required methods fn plugin_info(&self) -> PluginInfo; fn info_to_hash(&self, info: B::Info) -> Option<HashMap<String, String>>; fn open_builder(&self, args: &OpenArgs) -> Option<Self::Open>; fn create_builder( &self, args: &CreateArgs<Self::CreateArgs>, ) -> Option<Self::Create>; // Provided methods fn handle_plugin_info( &self, ) -> Result<HashMap<String, String>, ErrorResponse> { ... } fn handle_settings( &self, args: &CreateArgs<Self::CreateArgs>, ) -> Result<Vec<u8>, ErrorResponse> { ... } fn handle_open( &self, args: &OpenArgs, settings: &[u8], ) -> Result<B, ErrorResponse> { ... } fn handle_create( &self, args: &CreateArgs<Self::CreateArgs>, header: &[u8], overwrite: bool, ) -> Result<B, ErrorResponse> { ... } fn handle_id_size(&self) -> Result<usize, ErrorResponse> { ... } fn handle_block_size(&self, backend: &B) -> Result<u32, ErrorResponse> { ... } fn handle_id_to_bytes(&self, str: &str) -> Result<Vec<u8>, ErrorResponse> { ... } fn handle_id_to_string(&self, bytes: &[u8]) -> Result<String, ErrorResponse> { ... } fn handle_info( &self, backend: &B, ) -> Result<HashMap<String, String>, ErrorResponse> { ... } fn handle_aquire( &self, backend: &mut B, bytes: &[u8], ) -> Result<Vec<u8>, ErrorResponse> { ... } fn handle_release( &self, backend: &mut B, id: &[u8], ) -> Result<(), ErrorResponse> { ... } fn handle_read_header<T: ReceiveHeader<B>>( &self, header: &mut T, ) -> Result<Vec<u8>, ErrorResponse> { ... } fn handle_write_header( &self, backend: &mut B, header: &[u8], ) -> Result<(), ErrorResponse> { ... } fn handle_read( &self, backend: &mut B, id: &[u8], ) -> Result<Vec<u8>, ErrorResponse> { ... } fn handle_write( &self, backend: &mut B, id: &[u8], bytes: &[u8], ) -> Result<usize, ErrorResponse> { ... } fn handle_delete(&self, backend: B) -> Result<(), ErrorResponse> { ... } fn handle_quit(&self) -> Result<(), ErrorResponse> { ... }
}
Expand description

Trait enriches the generic implementation of the plugin with plugin-specific behavior.

You need to implement a set of functions that provide plugin-specific information.

There are several handle_* functions, which are already implemented. They encapsulates the handling for all the request types.

Required Associated Types§

Source

type CreateArgs: Args

Extra (plugin-specific) arguments passed to the create command.

Source

type Create: Create<B>

The create builder for the attached backend.

Source

type Open: Open<B>

The open builder for the attached backend.

Required Methods§

Source

fn plugin_info(&self) -> PluginInfo

Returns information of the plugin.

Source

fn info_to_hash(&self, info: B::Info) -> Option<HashMap<String, String>>

Converts the given info into a HashMap.

The hash is send back to the nuts-tool and displayed to the user. So you are advised to choose good, human readable keys.

On success the info-hash wrapped into a Some value is returned. If you cannot create the hash None is returned.

Source

fn open_builder(&self, args: &OpenArgs) -> Option<Self::Open>

Creates a builder instance used to open an already existing backend instance.

Source

fn create_builder( &self, args: &CreateArgs<Self::CreateArgs>, ) -> Option<Self::Create>

Creates a builder instance used to create a new backend instance.

Provided Methods§

Source

fn handle_plugin_info(&self) -> Result<HashMap<String, String>, ErrorResponse>

Handles the Request::PluginInfo command.

Source

fn handle_settings( &self, args: &CreateArgs<Self::CreateArgs>, ) -> Result<Vec<u8>, ErrorResponse>

Handles the Request::Settings command.

Source

fn handle_open( &self, args: &OpenArgs, settings: &[u8], ) -> Result<B, ErrorResponse>

Handles the Request::Open command.

Source

fn handle_create( &self, args: &CreateArgs<Self::CreateArgs>, header: &[u8], overwrite: bool, ) -> Result<B, ErrorResponse>

Handles the Request::Create command.

Source

fn handle_id_size(&self) -> Result<usize, ErrorResponse>

Handles the Request::IdSize command.

Source

fn handle_block_size(&self, backend: &B) -> Result<u32, ErrorResponse>

Handles the Request::BlockSize command.

Source

fn handle_id_to_bytes(&self, str: &str) -> Result<Vec<u8>, ErrorResponse>

Handles the Request::IdToBytes command.

Source

fn handle_id_to_string(&self, bytes: &[u8]) -> Result<String, ErrorResponse>

Handles the Request::IdToString command.

Source

fn handle_info( &self, backend: &B, ) -> Result<HashMap<String, String>, ErrorResponse>

Handles the Request::Info command.

Source

fn handle_aquire( &self, backend: &mut B, bytes: &[u8], ) -> Result<Vec<u8>, ErrorResponse>

Handles the Request::Aquire command.

Source

fn handle_release( &self, backend: &mut B, id: &[u8], ) -> Result<(), ErrorResponse>

Handles the Request::Release command.

Source

fn handle_read_header<T: ReceiveHeader<B>>( &self, header: &mut T, ) -> Result<Vec<u8>, ErrorResponse>

Handles the Request::ReadHeader command.

Source

fn handle_write_header( &self, backend: &mut B, header: &[u8], ) -> Result<(), ErrorResponse>

Handles the Request::WriteHeader command.

Source

fn handle_read( &self, backend: &mut B, id: &[u8], ) -> Result<Vec<u8>, ErrorResponse>

Handles the Request::Read command.

Source

fn handle_write( &self, backend: &mut B, id: &[u8], bytes: &[u8], ) -> Result<usize, ErrorResponse>

Handles the Request::Write command.

Source

fn handle_delete(&self, backend: B) -> Result<(), ErrorResponse>

Source

fn handle_quit(&self) -> Result<(), ErrorResponse>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§