1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::impl_::sodium_ctx::SodiumCtx as SodiumCtxImpl;
use crate::Cell;
use crate::CellLoop;
use crate::CellSink;
use crate::Stream;
use crate::StreamLoop;
use crate::StreamSink;

#[derive(Clone)]
pub struct SodiumCtx {
    pub impl_: SodiumCtxImpl,
}

impl Default for SodiumCtx {
    fn default() -> SodiumCtx {
        SodiumCtx::new()
    }
}

impl SodiumCtx {
    pub fn new() -> SodiumCtx {
        SodiumCtx {
            impl_: SodiumCtxImpl::new(),
        }
    }

    pub fn new_cell<A: Clone + Send + 'static>(&self, a: A) -> Cell<A> {
        Cell::new(self, a)
    }

    pub fn new_stream<A: Clone + Send + 'static>(&self) -> Stream<A> {
        Stream::new(self)
    }

    pub fn new_cell_sink<A: Clone + Send + 'static>(&self, a: A) -> CellSink<A> {
        CellSink::new(self, a)
    }

    pub fn new_stream_sink<A: Clone + Send + 'static>(&self) -> StreamSink<A> {
        StreamSink::new(self)
    }

    pub fn new_cell_loop<A: Clone + Send + 'static>(&self) -> CellLoop<A> {
        CellLoop::new(self)
    }

    pub fn new_stream_loop<A: Clone + Send + 'static>(&self) -> StreamLoop<A> {
        StreamLoop::new(self)
    }

    pub fn new_stream_sink_with_coalescer<
        A: Clone + Send + 'static,
        COALESCER: FnMut(&A, &A) -> A + Send + 'static,
    >(
        &self,
        coalescer: COALESCER,
    ) -> StreamSink<A> {
        StreamSink::new_with_coalescer(self, coalescer)
    }

    pub fn transaction<R, K: FnOnce() -> R>(&self, k: K) -> R {
        self.impl_.transaction(k)
    }
}