[−][src]Struct milter::DataHandle
A handle on user data stored in the callback context.
DataHandle<T>
serves as an accessor to connection-local data T
that can
be shared across callback functions within a connection.
Data life cycle
By design, data life cycle management is not automatic. It is the responsibility of a milter implementation to manage the data’s life cycle by reacquiring and disposing of context data (including associated resources such as file handles etc.) at an appropriate time in the callback flow.
As a rule of thumb, every path through the callback flow must have a final
call to take
.
Methods
impl<T> DataHandle<T>
[src]
pub fn replace(&mut self, data: T) -> Result<Option<T>>
[src]
Hands over data into the context, returning current context data if present.
Errors
An error variant is returned if the milter library encounters an error.
pub fn take(&mut self) -> Result<Option<T>>
[src]
Takes ownership of the current context data if present, removing it from the context.
Errors
An error variant is returned if the milter library encounters an error.
pub fn borrow(&self) -> Option<&T>
[src]
Returns a reference to (borrows) the current context data if present.
Examples
if let Some(data) = context.data.borrow() { println!("{}", data); }
pub fn borrow_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to (mutably borrows) the current context data if present.
Examples
if let Some(msg_count) = context.data.borrow_mut() { *msg_count += 1; }
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for DataHandle<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for DataHandle<T>
impl<T> !Sync for DataHandle<T>
impl<T> Unpin for DataHandle<T>
impl<T> UnwindSafe for DataHandle<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,