@@ -64,6 +64,29 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
64
64
/// child (nested) transactions. Each transaction belongs to one
65
65
/// thread. A `BadRslot` error will be thrown when multiple read
66
66
/// transactions exists on the same thread.
67
+ ///
68
+ /// # Example
69
+ ///
70
+ /// This example shows that the `RoTxn<'_, WithTls>` cannot be sent between threads.
71
+ ///
72
+ /// ```compile_fail
73
+ /// use std::fs;
74
+ /// use std::path::Path;
75
+ /// use heed::{EnvOpenOptions, Database, EnvFlags};
76
+ /// use heed::types::*;
77
+ ///
78
+ /// /// Checks, at compile time, that a type can be sent accross threads.
79
+ /// fn is_sendable<S: Send>(_x: S) {}
80
+ ///
81
+ /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
82
+ /// let mut env_builder = EnvOpenOptions::new().read_txn_with_tls();
83
+ /// let dir = tempfile::tempdir().unwrap();
84
+ /// let env = unsafe { env_builder.open(dir.path())? };
85
+ ///
86
+ /// let rtxn = env.read_txn()?;
87
+ /// is_sendable(rtxn);
88
+ /// # Ok(()) }
89
+ /// ```
67
90
pub fn read_txn_with_tls ( self ) -> EnvOpenOptions < WithTls > {
68
91
let Self { map_size, max_readers, max_dbs, flags, _tls_marker : _ } = self ;
69
92
EnvOpenOptions { map_size, max_readers, max_dbs, flags, _tls_marker : PhantomData }
@@ -75,6 +98,30 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
75
98
/// A thread can use any number of read transactions at a time on
76
99
/// the same thread. Read transactions can be moved in between
77
100
/// threads (`Send`).
101
+ ///
102
+ ///
103
+ /// # Example
104
+ ///
105
+ /// This example shows that the `RoTxn<'_, WithoutTls>` can be sent between threads.
106
+ ///
107
+ /// ```
108
+ /// use std::fs;
109
+ /// use std::path::Path;
110
+ /// use heed::{EnvOpenOptions, Database, EnvFlags};
111
+ /// use heed::types::*;
112
+ ///
113
+ /// /// Checks, at compile time, that a type can be sent accross threads.
114
+ /// fn is_sendable<S: Send>(_x: S) {}
115
+ ///
116
+ /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
117
+ /// let mut env_builder = EnvOpenOptions::new().read_txn_without_tls();
118
+ /// let dir = tempfile::tempdir().unwrap();
119
+ /// let env = unsafe { env_builder.open(dir.path())? };
120
+ ///
121
+ /// let rtxn = env.read_txn()?;
122
+ /// is_sendable(rtxn);
123
+ /// # Ok(()) }
124
+ /// ```
78
125
pub fn read_txn_without_tls ( self ) -> EnvOpenOptions < WithoutTls > {
79
126
let Self { map_size, max_readers, max_dbs, flags, _tls_marker : _ } = self ;
80
127
EnvOpenOptions { map_size, max_readers, max_dbs, flags, _tls_marker : PhantomData }
0 commit comments