Skip to main content

ExtensionRegistry

Struct ExtensionRegistry 

Source
pub struct ExtensionRegistry { /* private fields */ }
Expand description

A registry for extension field handlers per RFC 7822.

This allows applications to register custom handlers for non-NTS extension field types. The registry dispatches incoming extension fields to the appropriate handler based on field type.

§Examples

use ntp_proto::extension::{ExtensionRegistry, ExtensionHandler, ExtensionField};
use std::io;

// Define a custom handler
struct MyHandler;

impl ExtensionHandler for MyHandler {
    fn field_type(&self) -> u16 {
        0x4000  // Custom field type
    }

    fn handle(&self, value: &[u8]) -> io::Result<()> {
        println!("Received extension field with {} bytes", value.len());
        Ok(())
    }
}

// Create registry and register handler
let mut registry = ExtensionRegistry::new();
registry.register(Box::new(MyHandler));

// Dispatch an extension field
let field = ExtensionField {
    field_type: 0x4000,
    value: vec![1, 2, 3, 4],
};
registry.dispatch(&field).unwrap();

Implementations§

Source§

impl ExtensionRegistry

Source

pub fn new() -> ExtensionRegistry

Create a new empty extension field registry.

Source

pub fn register(&mut self, handler: Box<dyn ExtensionHandler>)

Register a handler for a specific extension field type.

If a handler for this field type is already registered, it will be replaced.

Source

pub fn dispatch(&self, field: &ExtensionField) -> Result<(), Error>

Dispatch an extension field to the registered handler.

Returns Ok(()) if a handler was found and successfully processed the field. Returns an error if no handler is registered for this field type or if the handler returns an error.

Source

pub fn dispatch_all( &self, fields: &[ExtensionField], require_handlers: bool, ) -> Result<(), Error>

Dispatch all extension fields in a list.

Processes each field in sequence. Stops and returns an error on the first failure. Ignores fields with no registered handler unless require_handlers is true.

Source

pub fn has_handler(&self, field_type: u16) -> bool

Check if a handler is registered for the given field type.

Source

pub fn len(&self) -> usize

Return the number of registered handlers.

Source

pub fn is_empty(&self) -> bool

Return true if no handlers are registered.

Trait Implementations§

Source§

impl Default for ExtensionRegistry

Source§

fn default() -> ExtensionRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.