sodium_rust/stream_loop.rs
1use crate::impl_::stream_loop::StreamLoop as StreamLoopImpl;
2use crate::SodiumCtx;
3use crate::Stream;
4
5/// A forward reference of a [`Stream`] for creating dependency loops.
6pub struct StreamLoop<A> {
7 pub impl_: StreamLoopImpl<A>,
8}
9
10impl<A: Send + Clone + 'static> StreamLoop<A> {
11 /// Create a new `StreamLoop` in the given context.
12 pub fn new(sodium_ctx: &SodiumCtx) -> StreamLoop<A> {
13 StreamLoop {
14 impl_: StreamLoopImpl::new(&sodium_ctx.impl_),
15 }
16 }
17
18 /// Return a [`Stream`] that is equivalent to this `StreamLoop`
19 /// once it has been resolved by calling
20 /// [`loop_`][StreamLoop::loop_].
21 pub fn stream(&self) -> Stream<A> {
22 Stream {
23 impl_: self.impl_.stream(),
24 }
25 }
26
27 /// Resolve the loop to specify what this `StreamLoop` was a
28 /// forward reference to.
29 ///
30 /// This function _must_ be invoked in the same transaction as the
31 /// place where the `StreamLoop` is used. This requires you to
32 /// create an explicit transaction, either with
33 /// [`SodiumCtx::transaction`] or
34 /// [`Transaction::new`][crate::Transaction::new].
35 pub fn loop_(&self, sa: &Stream<A>) {
36 self.impl_.loop_(&sa.impl_);
37 }
38}