[−][src]Struct milter::DataHandle
A handle on user data stored in the callback context.
DataHandle
serves as an accessor to connection-local data 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(&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(&self) -> Result<Option<T>>
[src]
Takes ownership of the current context data if present, and removes it from the context.
Errors
An error variant is returned if the milter library encounters an error.
pub fn borrow(&self) -> Result<Option<Ref<T>>>
[src]
Returns a reference to (borrows) the current context data if present.
It is the client’s responsibility to only call this when appropriate, that is, when the data is not already mutably borrowed.
Errors
An error variant is returned if the data is currently mutably borrowed.
Examples
if let Some(data) = context.data.borrow()? { println!("{}", data); }
pub fn borrow_mut(&self) -> Result<Option<RefMut<T>>>
[src]
Returns a mutable reference to (mutably borrows) the current context data if present.
It is the client’s responsibility to only call this when appropriate, that is, when the data is not already borrowed.
Errors
An error variant is returned if the data is currently borrowed.
Examples
if let Some(mut msg_count) = context.data.borrow_mut()? { *msg_count += 1; }
Trait Implementations
Auto Trait Implementations
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,
impl<T> !RefUnwindSafe for DataHandle<T>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,